Merged revisions 11544-11580 via svnmerge from
[wvapps.git] / nitlog / parser.inc.php
blob9429893ab704c655d8a00a26a06fcfbeb15bbde1
1 <?php
3 function match_entrytitle( $line1 )
5 preg_match_all( "{^\s*<b>(.*)</b>\s*$}m", $line1, $matches );
6 return join('; ', $matches[1]);
9 function get_entrytitle( $when, $day )
11 $file = file( "$when/$day" );
12 return match_entrytitle( join('', $file) );
15 function do_entrycontent( $when, $day )
17 global $topdir;
18 global $size;
20 $inlist = false;
22 $entrylines = array( "<!-- start of entry $when/$day -->\n" );
24 $file = file( "$when/$day" );
25 // if ( match_entrytitle( $file[0] ) ) $file[0] = "";
27 foreach( $file as $line ) {
28 if( substr( $line, 0, 6 ) === 'image ' ) {
29 $num = substr( $line, 6, 4 );
30 $caption = substr( $line, 10 );
31 $httpdir = "../$topdir/$when";
33 $lg = "img_$num"."_lg.jpg";
34 $sm = "img_$num"."_sm.jpg";
35 if( !file_exists( "$when/$lg" ) )
36 $lg = "img_$num"."_800.jpg";
37 if( !file_exists( "$when/$sm" ) )
38 $sm = "img_$num"."_400.jpg";
40 if( file_exists( "$when/$sm" ) ) {
41 $big = file_exists( "$when/$lg" );
42 $link1 = $big ? "<a href=\"$httpdir/$lg\">" : "";
43 $link2 = $big ? "</a>" : "";
44 array_push( $entrylines,
45 "<center><table border=0>" .
46 "<tr><td align=center>$link1<img " .
47 "border=0 src=\"$httpdir/$sm\" " .
48 "alt=\"[image]\">$link2<br>\n" .
49 "<i>$caption</i></td></tr></table></center>\n" );
51 continue;
53 } elseif( substr( $line, 0, 9 ) === 'pngimage ' ) {
54 $num = substr( $line, 9, 4 );
55 $caption = substr( $line, 13 );
56 $httpdir = "../$topdir/$when";
58 $lg = "img_$num"."_lg.png";
59 $sm = "img_$num"."_sm.png";
60 if( !file_exists( "$when/$lg" ) )
61 $lg = "img_$num"."_800.png";
62 if( !file_exists( "$when/$sm" ) )
63 $sm = "img_$num"."_400.png";
65 if( file_exists( "$when/$sm" ) ) {
66 $big = file_exists( "$when/$lg" );
67 $link1 = $big ? "<a href=\"$httpdir/$lg\">" : "";
68 $link2 = $big ? "</a>" : "";
69 array_push( $entrylines,
70 "<center><table border=0>" .
71 "<tr><td align=center>$link1<img " .
72 "border=0 src=\"$httpdir/$sm\" " .
73 "alt=\"[image]\">$link2<br>\n" .
74 "<i>$caption</i></td></tr></table></center>\n" );
76 continue;
78 } elseif( substr( $line, 0, 8 ) === 'imglink ' ) {
79 $num = substr( $line, 8, 4 );
80 $caption = substr( $line, 12 );
81 $httpdir = "../$topdir/$when";
83 $sm = "img_$num"."_sm.jpg";
84 $lg = "img_$num"."_lg.jpg";
85 $hg = "img_$num.jpg";
86 if( !file_exists( "$when/$sm" ) )
87 $sm = "img_$num"."_800.jpg";
89 $havehuge = file_exists( "$when/$hg" );
90 $havebig = file_exists( "$when/$lg" );
91 $havesmall = file_exists( "$when/$sm" );
93 $dash = false;
94 $tmp = '';
95 if( $havehuge ) {
96 $tmp .= "<a href=\"$httpdir/img_$num.jpg\">huge</a>";
97 $dash = true;
99 if( $havebig ) {
100 if( $dash )
101 $tmp .= '-';
102 $tmp .= "<a href=\"$httpdir/$lg\">big</a>";
103 $dash = true;
105 if( $havesmall ) {
106 if( $dash )
107 $tmp .= '-';
108 $tmp .= "<a href=\"$httpdir/$sm\">small</a>";
111 array_push( $entrylines, "$tmp&mdash;$caption<br>\n" );
112 continue;
114 } elseif( substr( $line, 0, 6 ) === 'thumb ' ) {
115 $num = substr( $line, 6, 4 );
116 $httpdir = "../$topdir/$when";
118 $th = "img_$num"."_th.jpg";
119 if( file_exists( "$when/$th" ) ) {
120 if( $size )
121 $sizebit = "&size=$size";
123 array_push( $entrylines,
124 "<a name=\"$num\">" .
125 "<a href=\"img.php?num=$num&when=$when&day=$day" .
126 "$sizebit\">" .
127 "<img border=0 src=\"$httpdir/$th\"></a>\n" );
129 continue;
131 } elseif( substr( $line, 0, 2 ) === '- ' ) {
132 $tmp = '';
133 if( $inlist == false ) {
134 $tmp .= "<ul>\n";
135 $inlist = true;
136 $needbr = false;
138 if( $needbr == true ) {
139 $tmp .= "<br>\n";
140 $needbr = false;
142 array_push( $entrylines,
143 "$tmp<li>" . substr( $line, 2 ) . "</li>\n" );
144 continue;
146 } else if( strlen( $line ) <= 1 ) {
147 if( $inlist )
148 $needbr = true;
149 else
150 array_push( $entrylines, "<p>\n" );
151 continue;
153 } else {
154 if( $inlist == true ) {
155 array_push( $entrylines, "</ul>\n" );
156 $inlist = false;
160 array_push( $entrylines, $line );
163 array_push( $entrylines, "<!-- end of entry $when/$day -->\n" );
165 return( $entrylines );