Fossil SCM
Share RSS HTML content handling between web and CLI feeds.
Commit
057236b8c9fc5f01d704fd12a58f14068279250cb551ac078eb8a7b755d67be4
Parent
07dadca733d6aa9…
1 file changed
+88
-92
+88
-92
| --- src/rss.c | ||
| +++ src/rss.c | ||
| @@ -205,10 +205,79 @@ | ||
| 205 | 205 | z = zValEnd; |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | if( zLast<zEnd ) blob_append(pOut, zLast, (int)(zEnd - zLast)); |
| 209 | 209 | } |
| 210 | + | |
| 211 | +/* | |
| 212 | +** Render RSS item HTML content into pOut when applicable. | |
| 213 | +** Return 1 if HTML content was produced, 0 if not, and -1 if the | |
| 214 | +** item should be skipped entirely. | |
| 215 | +** If pzAltLink is not NULL, it may be filled with an alternate link id | |
| 216 | +** for event pages. It remains NULL for non-technote items. The caller | |
| 217 | +** must free that result. | |
| 218 | +*/ | |
| 219 | +static int rss_render_item_html( | |
| 220 | + Blob *pOut, | |
| 221 | + char **pzAltLink, | |
| 222 | + int rid, | |
| 223 | + const char *zEType, | |
| 224 | + const char *zBase, | |
| 225 | + const char *zTop, | |
| 226 | + int bFilterPrivate | |
| 227 | +){ | |
| 228 | + Manifest *pPost = 0; | |
| 229 | + int rc = 0; | |
| 230 | + Blob normalized = BLOB_INITIALIZER; | |
| 231 | + if( pzAltLink ) *pzAltLink = 0; | |
| 232 | + if( pOut==0 || zEType==0 ) return 0; | |
| 233 | + if( zEType[0]=='f' ){ | |
| 234 | + if( bFilterPrivate && content_is_private(rid) ) return -1; | |
| 235 | + pPost = manifest_get(rid, CFTYPE_FORUM, 0); | |
| 236 | + if( pPost ){ | |
| 237 | + forum_render_to_html(pOut, pPost->zMimetype, pPost->zWiki); | |
| 238 | + } | |
| 239 | + }else if( zEType[0]=='e' ){ | |
| 240 | + if( pzAltLink ) *pzAltLink = technote_render_to_html(pOut, rid); | |
| 241 | + else free(technote_render_to_html(pOut, rid)); | |
| 242 | + } | |
| 243 | + if( pPost ) manifest_destroy(pPost); | |
| 244 | + if( blob_size(pOut)>0 ){ | |
| 245 | + rss_make_abs_links(&normalized, zBase, zTop, blob_str(pOut), blob_size(pOut)); | |
| 246 | + blob_reset(pOut); | |
| 247 | + blob_append(pOut, blob_str(&normalized), blob_size(&normalized)); | |
| 248 | + rc = 1; | |
| 249 | + } | |
| 250 | + blob_reset(&normalized); | |
| 251 | + return rc; | |
| 252 | +} | |
| 253 | + | |
| 254 | +/* | |
| 255 | +** Emit HTML content:encoded for the current web RSS item. | |
| 256 | +*/ | |
| 257 | +static void rss_web_emit_html_content(Blob *pHtml){ | |
| 258 | + Blob cdata = BLOB_INITIALIZER; | |
| 259 | + @ <dc:format>text/html</dc:format> | |
| 260 | + @ <content:encoded><![CDATA[ | |
| 261 | + rss_cdata_append(&cdata, blob_str(pHtml), blob_size(pHtml)); | |
| 262 | + cgi_append_content(blob_str(&cdata), blob_size(&cdata)); | |
| 263 | + blob_reset(&cdata); | |
| 264 | + @ ]]></content:encoded> | |
| 265 | +} | |
| 266 | + | |
| 267 | +/* | |
| 268 | +** Emit HTML content:encoded for the current CLI RSS item. | |
| 269 | +*/ | |
| 270 | +static void rss_cli_emit_html_content(Blob *pHtml){ | |
| 271 | + Blob cdata = BLOB_INITIALIZER; | |
| 272 | + fossil_print("<dc:format>text/html</dc:format>\n"); | |
| 273 | + fossil_print("<content:encoded><![CDATA["); | |
| 274 | + rss_cdata_append(&cdata, blob_str(pHtml), blob_size(pHtml)); | |
| 275 | + fossil_print("%s", blob_str(&cdata)); | |
| 276 | + blob_reset(&cdata); | |
| 277 | + fossil_print("]]></content:encoded>\n"); | |
| 278 | +} | |
| 210 | 279 | |
| 211 | 280 | /* |
| 212 | 281 | ** WEBPAGE: timeline.rss |
| 213 | 282 | ** URL: /timeline.rss?y=TYPE&n=LIMIT&tkt=HASH&tag=TAG&wiki=NAME&name=FILENAME |
| 214 | 283 | ** |
| @@ -379,14 +448,13 @@ | ||
| 379 | 448 | char *zSuffix = 0; |
| 380 | 449 | char *zDate; |
| 381 | 450 | int nChild = db_column_int(&q, 6); |
| 382 | 451 | int nParent = db_column_int(&q, 7); |
| 383 | 452 | const char *zTagList = db_column_text(&q, 8); |
| 384 | - Manifest *pPost = 0; | |
| 385 | 453 | char *zTechnoteId = 0; |
| 386 | 454 | Blob contentHtml = BLOB_INITIALIZER; |
| 387 | - int bForumContent = 0; | |
| 455 | + int bHasContent = 0; | |
| 388 | 456 | time_t ts; |
| 389 | 457 | |
| 390 | 458 | if( zTagList && zTagList[0]==0 ) zTagList = 0; |
| 391 | 459 | ts = (time_t)((db_column_double(&q,2) - 2440587.5)*86400.0); |
| 392 | 460 | zDate = cgi_rfc822_datestamp(ts); |
| @@ -410,68 +478,33 @@ | ||
| 410 | 478 | |
| 411 | 479 | if( zTagList ){ |
| 412 | 480 | zSuffix = mprintf(" (tags: %s)", zTagList); |
| 413 | 481 | } |
| 414 | 482 | |
| 415 | - if( zEType[0]=='f' ){ | |
| 416 | - if( !g.perm.ModForum && content_is_private(rid) ){ | |
| 417 | - free(zDate); | |
| 418 | - free(zSuffix); | |
| 419 | - continue; | |
| 420 | - } | |
| 421 | - pPost = manifest_get(rid, CFTYPE_FORUM, 0); | |
| 422 | - if( pPost ){ | |
| 423 | - forum_render_to_html(&contentHtml, pPost->zMimetype, pPost->zWiki); | |
| 424 | - if( blob_size(&contentHtml)>0 ){ | |
| 425 | - Blob normalized = BLOB_INITIALIZER; | |
| 426 | - rss_make_abs_links(&normalized, blob_str(&base), | |
| 427 | - blob_str(&top), blob_str(&contentHtml), | |
| 428 | - blob_size(&contentHtml)); | |
| 429 | - blob_reset(&contentHtml); | |
| 430 | - blob_append(&contentHtml, blob_str(&normalized), | |
| 431 | - blob_size(&normalized)); | |
| 432 | - blob_reset(&normalized); | |
| 433 | - bForumContent = 1; | |
| 434 | - } | |
| 435 | - } | |
| 436 | - }else if( zEType[0]=='e' ){ | |
| 437 | - zTechnoteId = technote_render_to_html(&contentHtml, rid); | |
| 438 | - if( blob_size(&contentHtml)>0 ){ | |
| 439 | - Blob normalized = BLOB_INITIALIZER; | |
| 440 | - rss_make_abs_links(&normalized, blob_str(&base), | |
| 441 | - blob_str(&top), blob_str(&contentHtml), | |
| 442 | - blob_size(&contentHtml)); | |
| 443 | - blob_reset(&contentHtml); | |
| 444 | - blob_append(&contentHtml, blob_str(&normalized), | |
| 445 | - blob_size(&normalized)); | |
| 446 | - blob_reset(&normalized); | |
| 447 | - bForumContent = 1; | |
| 448 | - } | |
| 483 | + bHasContent = rss_render_item_html(&contentHtml, &zTechnoteId, rid, zEType, | |
| 484 | + blob_str(&base), blob_str(&top), | |
| 485 | + !g.perm.ModForum); | |
| 486 | + if( bHasContent<0 ){ | |
| 487 | + free(zDate); | |
| 488 | + free(zSuffix); | |
| 489 | + continue; | |
| 449 | 490 | } |
| 450 | 491 | @ <item> |
| 451 | 492 | @ <title>%s(zPrefix)%h(zCom)%h(zSuffix)</title> |
| 452 | - if( zEType[0]=='e' && zTechnoteId!=0 ){ | |
| 453 | - @ <link>%s(g.zBaseURL)/technote/%s(zTechnoteId)</link> | |
| 493 | + if( zTechnoteId!=0 ){ | |
| 494 | + @ <link>%s(g.zBaseURL)/info/%s(zTechnoteId)</link> | |
| 454 | 495 | }else{ |
| 455 | 496 | @ <link>%s(g.zBaseURL)/info/%s(zId)</link> |
| 456 | 497 | } |
| 457 | 498 | @ <description>%s(zPrefix)%h(zCom)%h(zSuffix)</description> |
| 458 | 499 | @ <pubDate>%s(zDate)</pubDate> |
| 459 | 500 | @ <dc:creator>%h(zAuthor)</dc:creator> |
| 460 | 501 | @ <guid>%s(g.zBaseURL)/info/%s(zId)</guid> |
| 461 | - if( bForumContent ){ | |
| 462 | - Blob cdata = BLOB_INITIALIZER; | |
| 463 | - @ <dc:format>text/html</dc:format> | |
| 464 | - @ <content:encoded><![CDATA[ | |
| 465 | - rss_cdata_append(&cdata, blob_str(&contentHtml), | |
| 466 | - blob_size(&contentHtml)); | |
| 467 | - cgi_append_content(blob_str(&cdata), blob_size(&cdata)); | |
| 468 | - blob_reset(&cdata); | |
| 469 | - @ ]]></content:encoded> | |
| 502 | + if( bHasContent ){ | |
| 503 | + rss_web_emit_html_content(&contentHtml); | |
| 470 | 504 | } |
| 471 | 505 | @ </item> |
| 472 | - if( pPost ) manifest_destroy(pPost); | |
| 473 | 506 | free(zTechnoteId); |
| 474 | 507 | blob_reset(&contentHtml); |
| 475 | 508 | free(zDate); |
| 476 | 509 | free(zSuffix); |
| 477 | 510 | nLine++; |
| @@ -658,14 +691,13 @@ | ||
| 658 | 691 | char *zSuffix = 0; |
| 659 | 692 | char *zDate; |
| 660 | 693 | int nChild = db_column_int(&q, 6); |
| 661 | 694 | int nParent = db_column_int(&q, 7); |
| 662 | 695 | const char *zTagList = db_column_text(&q, 8); |
| 663 | - Manifest *pPost = 0; | |
| 664 | 696 | char *zTechnoteId = 0; |
| 665 | 697 | Blob contentHtml = BLOB_INITIALIZER; |
| 666 | - int bForumContent = 0; | |
| 698 | + int bHasContent = 0; | |
| 667 | 699 | time_t ts; |
| 668 | 700 | |
| 669 | 701 | if( zTagList && zTagList[0]==0 ) zTagList = 0; |
| 670 | 702 | ts = (time_t)((db_column_double(&q,2) - 2440587.5)*86400.0); |
| 671 | 703 | zDate = cgi_rfc822_datestamp(ts); |
| @@ -689,63 +721,27 @@ | ||
| 689 | 721 | |
| 690 | 722 | if( zTagList ){ |
| 691 | 723 | zSuffix = mprintf(" (tags: %s)", zTagList); |
| 692 | 724 | } |
| 693 | 725 | |
| 694 | - if( zEType[0]=='f' ){ | |
| 695 | - pPost = manifest_get(rid, CFTYPE_FORUM, 0); | |
| 696 | - if( pPost ){ | |
| 697 | - forum_render_to_html(&contentHtml, pPost->zMimetype, pPost->zWiki); | |
| 698 | - if( blob_size(&contentHtml)>0 ){ | |
| 699 | - Blob normalized = BLOB_INITIALIZER; | |
| 700 | - rss_make_abs_links(&normalized, blob_str(&base), | |
| 701 | - blob_str(&top), blob_str(&contentHtml), | |
| 702 | - blob_size(&contentHtml)); | |
| 703 | - blob_reset(&contentHtml); | |
| 704 | - blob_append(&contentHtml, blob_str(&normalized), | |
| 705 | - blob_size(&normalized)); | |
| 706 | - blob_reset(&normalized); | |
| 707 | - bForumContent = 1; | |
| 708 | - } | |
| 709 | - } | |
| 710 | - }else if( zEType[0]=='e' ){ | |
| 711 | - zTechnoteId = technote_render_to_html(&contentHtml, rid); | |
| 712 | - if( blob_size(&contentHtml)>0 ){ | |
| 713 | - Blob normalized = BLOB_INITIALIZER; | |
| 714 | - rss_make_abs_links(&normalized, blob_str(&base), | |
| 715 | - blob_str(&top), blob_str(&contentHtml), | |
| 716 | - blob_size(&contentHtml)); | |
| 717 | - blob_reset(&contentHtml); | |
| 718 | - blob_append(&contentHtml, blob_str(&normalized), | |
| 719 | - blob_size(&normalized)); | |
| 720 | - blob_reset(&normalized); | |
| 721 | - bForumContent = 1; | |
| 722 | - } | |
| 723 | - } | |
| 726 | + bHasContent = rss_render_item_html(&contentHtml, &zTechnoteId, rid, zEType, | |
| 727 | + blob_str(&base), blob_str(&top), 0); | |
| 724 | 728 | fossil_print("<item>"); |
| 725 | 729 | fossil_print("<title>%s%h%h</title>\n", zPrefix, zCom, zSuffix); |
| 726 | - if( zEType[0]=='e' && zTechnoteId!=0 ){ | |
| 727 | - fossil_print("<link>%s/technote/%s</link>\n", zBaseURL, zTechnoteId); | |
| 730 | + if( zTechnoteId!=0 ){ | |
| 731 | + fossil_print("<link>%s/info/%s</link>\n", zBaseURL, zTechnoteId); | |
| 728 | 732 | }else{ |
| 729 | 733 | fossil_print("<link>%s/info/%s</link>\n", zBaseURL, zId); |
| 730 | 734 | } |
| 731 | 735 | fossil_print("<description>%s%h%h</description>\n", zPrefix, zCom, zSuffix); |
| 732 | 736 | fossil_print("<pubDate>%s</pubDate>\n", zDate); |
| 733 | 737 | fossil_print("<dc:creator>%h</dc:creator>\n", zAuthor); |
| 734 | 738 | fossil_print("<guid>%s/info/%s</guid>\n", g.zBaseURL, zId); |
| 735 | - if( bForumContent ){ | |
| 736 | - Blob cdata = BLOB_INITIALIZER; | |
| 737 | - fossil_print("<dc:format>text/html</dc:format>\n"); | |
| 738 | - fossil_print("<content:encoded><![CDATA["); | |
| 739 | - rss_cdata_append(&cdata, blob_str(&contentHtml), | |
| 740 | - blob_size(&contentHtml)); | |
| 741 | - fossil_print("%s", blob_str(&cdata)); | |
| 742 | - blob_reset(&cdata); | |
| 743 | - fossil_print("]]></content:encoded>\n"); | |
| 739 | + if( bHasContent ){ | |
| 740 | + rss_cli_emit_html_content(&contentHtml); | |
| 744 | 741 | } |
| 745 | 742 | fossil_print("</item>\n"); |
| 746 | - if( pPost ) manifest_destroy(pPost); | |
| 747 | 743 | free(zTechnoteId); |
| 748 | 744 | blob_reset(&contentHtml); |
| 749 | 745 | free(zDate); |
| 750 | 746 | free(zSuffix); |
| 751 | 747 | nLine++; |
| 752 | 748 |
| --- src/rss.c | |
| +++ src/rss.c | |
| @@ -205,10 +205,79 @@ | |
| 205 | z = zValEnd; |
| 206 | } |
| 207 | } |
| 208 | if( zLast<zEnd ) blob_append(pOut, zLast, (int)(zEnd - zLast)); |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | ** WEBPAGE: timeline.rss |
| 213 | ** URL: /timeline.rss?y=TYPE&n=LIMIT&tkt=HASH&tag=TAG&wiki=NAME&name=FILENAME |
| 214 | ** |
| @@ -379,14 +448,13 @@ | |
| 379 | char *zSuffix = 0; |
| 380 | char *zDate; |
| 381 | int nChild = db_column_int(&q, 6); |
| 382 | int nParent = db_column_int(&q, 7); |
| 383 | const char *zTagList = db_column_text(&q, 8); |
| 384 | Manifest *pPost = 0; |
| 385 | char *zTechnoteId = 0; |
| 386 | Blob contentHtml = BLOB_INITIALIZER; |
| 387 | int bForumContent = 0; |
| 388 | time_t ts; |
| 389 | |
| 390 | if( zTagList && zTagList[0]==0 ) zTagList = 0; |
| 391 | ts = (time_t)((db_column_double(&q,2) - 2440587.5)*86400.0); |
| 392 | zDate = cgi_rfc822_datestamp(ts); |
| @@ -410,68 +478,33 @@ | |
| 410 | |
| 411 | if( zTagList ){ |
| 412 | zSuffix = mprintf(" (tags: %s)", zTagList); |
| 413 | } |
| 414 | |
| 415 | if( zEType[0]=='f' ){ |
| 416 | if( !g.perm.ModForum && content_is_private(rid) ){ |
| 417 | free(zDate); |
| 418 | free(zSuffix); |
| 419 | continue; |
| 420 | } |
| 421 | pPost = manifest_get(rid, CFTYPE_FORUM, 0); |
| 422 | if( pPost ){ |
| 423 | forum_render_to_html(&contentHtml, pPost->zMimetype, pPost->zWiki); |
| 424 | if( blob_size(&contentHtml)>0 ){ |
| 425 | Blob normalized = BLOB_INITIALIZER; |
| 426 | rss_make_abs_links(&normalized, blob_str(&base), |
| 427 | blob_str(&top), blob_str(&contentHtml), |
| 428 | blob_size(&contentHtml)); |
| 429 | blob_reset(&contentHtml); |
| 430 | blob_append(&contentHtml, blob_str(&normalized), |
| 431 | blob_size(&normalized)); |
| 432 | blob_reset(&normalized); |
| 433 | bForumContent = 1; |
| 434 | } |
| 435 | } |
| 436 | }else if( zEType[0]=='e' ){ |
| 437 | zTechnoteId = technote_render_to_html(&contentHtml, rid); |
| 438 | if( blob_size(&contentHtml)>0 ){ |
| 439 | Blob normalized = BLOB_INITIALIZER; |
| 440 | rss_make_abs_links(&normalized, blob_str(&base), |
| 441 | blob_str(&top), blob_str(&contentHtml), |
| 442 | blob_size(&contentHtml)); |
| 443 | blob_reset(&contentHtml); |
| 444 | blob_append(&contentHtml, blob_str(&normalized), |
| 445 | blob_size(&normalized)); |
| 446 | blob_reset(&normalized); |
| 447 | bForumContent = 1; |
| 448 | } |
| 449 | } |
| 450 | @ <item> |
| 451 | @ <title>%s(zPrefix)%h(zCom)%h(zSuffix)</title> |
| 452 | if( zEType[0]=='e' && zTechnoteId!=0 ){ |
| 453 | @ <link>%s(g.zBaseURL)/technote/%s(zTechnoteId)</link> |
| 454 | }else{ |
| 455 | @ <link>%s(g.zBaseURL)/info/%s(zId)</link> |
| 456 | } |
| 457 | @ <description>%s(zPrefix)%h(zCom)%h(zSuffix)</description> |
| 458 | @ <pubDate>%s(zDate)</pubDate> |
| 459 | @ <dc:creator>%h(zAuthor)</dc:creator> |
| 460 | @ <guid>%s(g.zBaseURL)/info/%s(zId)</guid> |
| 461 | if( bForumContent ){ |
| 462 | Blob cdata = BLOB_INITIALIZER; |
| 463 | @ <dc:format>text/html</dc:format> |
| 464 | @ <content:encoded><![CDATA[ |
| 465 | rss_cdata_append(&cdata, blob_str(&contentHtml), |
| 466 | blob_size(&contentHtml)); |
| 467 | cgi_append_content(blob_str(&cdata), blob_size(&cdata)); |
| 468 | blob_reset(&cdata); |
| 469 | @ ]]></content:encoded> |
| 470 | } |
| 471 | @ </item> |
| 472 | if( pPost ) manifest_destroy(pPost); |
| 473 | free(zTechnoteId); |
| 474 | blob_reset(&contentHtml); |
| 475 | free(zDate); |
| 476 | free(zSuffix); |
| 477 | nLine++; |
| @@ -658,14 +691,13 @@ | |
| 658 | char *zSuffix = 0; |
| 659 | char *zDate; |
| 660 | int nChild = db_column_int(&q, 6); |
| 661 | int nParent = db_column_int(&q, 7); |
| 662 | const char *zTagList = db_column_text(&q, 8); |
| 663 | Manifest *pPost = 0; |
| 664 | char *zTechnoteId = 0; |
| 665 | Blob contentHtml = BLOB_INITIALIZER; |
| 666 | int bForumContent = 0; |
| 667 | time_t ts; |
| 668 | |
| 669 | if( zTagList && zTagList[0]==0 ) zTagList = 0; |
| 670 | ts = (time_t)((db_column_double(&q,2) - 2440587.5)*86400.0); |
| 671 | zDate = cgi_rfc822_datestamp(ts); |
| @@ -689,63 +721,27 @@ | |
| 689 | |
| 690 | if( zTagList ){ |
| 691 | zSuffix = mprintf(" (tags: %s)", zTagList); |
| 692 | } |
| 693 | |
| 694 | if( zEType[0]=='f' ){ |
| 695 | pPost = manifest_get(rid, CFTYPE_FORUM, 0); |
| 696 | if( pPost ){ |
| 697 | forum_render_to_html(&contentHtml, pPost->zMimetype, pPost->zWiki); |
| 698 | if( blob_size(&contentHtml)>0 ){ |
| 699 | Blob normalized = BLOB_INITIALIZER; |
| 700 | rss_make_abs_links(&normalized, blob_str(&base), |
| 701 | blob_str(&top), blob_str(&contentHtml), |
| 702 | blob_size(&contentHtml)); |
| 703 | blob_reset(&contentHtml); |
| 704 | blob_append(&contentHtml, blob_str(&normalized), |
| 705 | blob_size(&normalized)); |
| 706 | blob_reset(&normalized); |
| 707 | bForumContent = 1; |
| 708 | } |
| 709 | } |
| 710 | }else if( zEType[0]=='e' ){ |
| 711 | zTechnoteId = technote_render_to_html(&contentHtml, rid); |
| 712 | if( blob_size(&contentHtml)>0 ){ |
| 713 | Blob normalized = BLOB_INITIALIZER; |
| 714 | rss_make_abs_links(&normalized, blob_str(&base), |
| 715 | blob_str(&top), blob_str(&contentHtml), |
| 716 | blob_size(&contentHtml)); |
| 717 | blob_reset(&contentHtml); |
| 718 | blob_append(&contentHtml, blob_str(&normalized), |
| 719 | blob_size(&normalized)); |
| 720 | blob_reset(&normalized); |
| 721 | bForumContent = 1; |
| 722 | } |
| 723 | } |
| 724 | fossil_print("<item>"); |
| 725 | fossil_print("<title>%s%h%h</title>\n", zPrefix, zCom, zSuffix); |
| 726 | if( zEType[0]=='e' && zTechnoteId!=0 ){ |
| 727 | fossil_print("<link>%s/technote/%s</link>\n", zBaseURL, zTechnoteId); |
| 728 | }else{ |
| 729 | fossil_print("<link>%s/info/%s</link>\n", zBaseURL, zId); |
| 730 | } |
| 731 | fossil_print("<description>%s%h%h</description>\n", zPrefix, zCom, zSuffix); |
| 732 | fossil_print("<pubDate>%s</pubDate>\n", zDate); |
| 733 | fossil_print("<dc:creator>%h</dc:creator>\n", zAuthor); |
| 734 | fossil_print("<guid>%s/info/%s</guid>\n", g.zBaseURL, zId); |
| 735 | if( bForumContent ){ |
| 736 | Blob cdata = BLOB_INITIALIZER; |
| 737 | fossil_print("<dc:format>text/html</dc:format>\n"); |
| 738 | fossil_print("<content:encoded><![CDATA["); |
| 739 | rss_cdata_append(&cdata, blob_str(&contentHtml), |
| 740 | blob_size(&contentHtml)); |
| 741 | fossil_print("%s", blob_str(&cdata)); |
| 742 | blob_reset(&cdata); |
| 743 | fossil_print("]]></content:encoded>\n"); |
| 744 | } |
| 745 | fossil_print("</item>\n"); |
| 746 | if( pPost ) manifest_destroy(pPost); |
| 747 | free(zTechnoteId); |
| 748 | blob_reset(&contentHtml); |
| 749 | free(zDate); |
| 750 | free(zSuffix); |
| 751 | nLine++; |
| 752 |
| --- src/rss.c | |
| +++ src/rss.c | |
| @@ -205,10 +205,79 @@ | |
| 205 | z = zValEnd; |
| 206 | } |
| 207 | } |
| 208 | if( zLast<zEnd ) blob_append(pOut, zLast, (int)(zEnd - zLast)); |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | ** Render RSS item HTML content into pOut when applicable. |
| 213 | ** Return 1 if HTML content was produced, 0 if not, and -1 if the |
| 214 | ** item should be skipped entirely. |
| 215 | ** If pzAltLink is not NULL, it may be filled with an alternate link id |
| 216 | ** for event pages. It remains NULL for non-technote items. The caller |
| 217 | ** must free that result. |
| 218 | */ |
| 219 | static int rss_render_item_html( |
| 220 | Blob *pOut, |
| 221 | char **pzAltLink, |
| 222 | int rid, |
| 223 | const char *zEType, |
| 224 | const char *zBase, |
| 225 | const char *zTop, |
| 226 | int bFilterPrivate |
| 227 | ){ |
| 228 | Manifest *pPost = 0; |
| 229 | int rc = 0; |
| 230 | Blob normalized = BLOB_INITIALIZER; |
| 231 | if( pzAltLink ) *pzAltLink = 0; |
| 232 | if( pOut==0 || zEType==0 ) return 0; |
| 233 | if( zEType[0]=='f' ){ |
| 234 | if( bFilterPrivate && content_is_private(rid) ) return -1; |
| 235 | pPost = manifest_get(rid, CFTYPE_FORUM, 0); |
| 236 | if( pPost ){ |
| 237 | forum_render_to_html(pOut, pPost->zMimetype, pPost->zWiki); |
| 238 | } |
| 239 | }else if( zEType[0]=='e' ){ |
| 240 | if( pzAltLink ) *pzAltLink = technote_render_to_html(pOut, rid); |
| 241 | else free(technote_render_to_html(pOut, rid)); |
| 242 | } |
| 243 | if( pPost ) manifest_destroy(pPost); |
| 244 | if( blob_size(pOut)>0 ){ |
| 245 | rss_make_abs_links(&normalized, zBase, zTop, blob_str(pOut), blob_size(pOut)); |
| 246 | blob_reset(pOut); |
| 247 | blob_append(pOut, blob_str(&normalized), blob_size(&normalized)); |
| 248 | rc = 1; |
| 249 | } |
| 250 | blob_reset(&normalized); |
| 251 | return rc; |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | ** Emit HTML content:encoded for the current web RSS item. |
| 256 | */ |
| 257 | static void rss_web_emit_html_content(Blob *pHtml){ |
| 258 | Blob cdata = BLOB_INITIALIZER; |
| 259 | @ <dc:format>text/html</dc:format> |
| 260 | @ <content:encoded><![CDATA[ |
| 261 | rss_cdata_append(&cdata, blob_str(pHtml), blob_size(pHtml)); |
| 262 | cgi_append_content(blob_str(&cdata), blob_size(&cdata)); |
| 263 | blob_reset(&cdata); |
| 264 | @ ]]></content:encoded> |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | ** Emit HTML content:encoded for the current CLI RSS item. |
| 269 | */ |
| 270 | static void rss_cli_emit_html_content(Blob *pHtml){ |
| 271 | Blob cdata = BLOB_INITIALIZER; |
| 272 | fossil_print("<dc:format>text/html</dc:format>\n"); |
| 273 | fossil_print("<content:encoded><![CDATA["); |
| 274 | rss_cdata_append(&cdata, blob_str(pHtml), blob_size(pHtml)); |
| 275 | fossil_print("%s", blob_str(&cdata)); |
| 276 | blob_reset(&cdata); |
| 277 | fossil_print("]]></content:encoded>\n"); |
| 278 | } |
| 279 | |
| 280 | /* |
| 281 | ** WEBPAGE: timeline.rss |
| 282 | ** URL: /timeline.rss?y=TYPE&n=LIMIT&tkt=HASH&tag=TAG&wiki=NAME&name=FILENAME |
| 283 | ** |
| @@ -379,14 +448,13 @@ | |
| 448 | char *zSuffix = 0; |
| 449 | char *zDate; |
| 450 | int nChild = db_column_int(&q, 6); |
| 451 | int nParent = db_column_int(&q, 7); |
| 452 | const char *zTagList = db_column_text(&q, 8); |
| 453 | char *zTechnoteId = 0; |
| 454 | Blob contentHtml = BLOB_INITIALIZER; |
| 455 | int bHasContent = 0; |
| 456 | time_t ts; |
| 457 | |
| 458 | if( zTagList && zTagList[0]==0 ) zTagList = 0; |
| 459 | ts = (time_t)((db_column_double(&q,2) - 2440587.5)*86400.0); |
| 460 | zDate = cgi_rfc822_datestamp(ts); |
| @@ -410,68 +478,33 @@ | |
| 478 | |
| 479 | if( zTagList ){ |
| 480 | zSuffix = mprintf(" (tags: %s)", zTagList); |
| 481 | } |
| 482 | |
| 483 | bHasContent = rss_render_item_html(&contentHtml, &zTechnoteId, rid, zEType, |
| 484 | blob_str(&base), blob_str(&top), |
| 485 | !g.perm.ModForum); |
| 486 | if( bHasContent<0 ){ |
| 487 | free(zDate); |
| 488 | free(zSuffix); |
| 489 | continue; |
| 490 | } |
| 491 | @ <item> |
| 492 | @ <title>%s(zPrefix)%h(zCom)%h(zSuffix)</title> |
| 493 | if( zTechnoteId!=0 ){ |
| 494 | @ <link>%s(g.zBaseURL)/info/%s(zTechnoteId)</link> |
| 495 | }else{ |
| 496 | @ <link>%s(g.zBaseURL)/info/%s(zId)</link> |
| 497 | } |
| 498 | @ <description>%s(zPrefix)%h(zCom)%h(zSuffix)</description> |
| 499 | @ <pubDate>%s(zDate)</pubDate> |
| 500 | @ <dc:creator>%h(zAuthor)</dc:creator> |
| 501 | @ <guid>%s(g.zBaseURL)/info/%s(zId)</guid> |
| 502 | if( bHasContent ){ |
| 503 | rss_web_emit_html_content(&contentHtml); |
| 504 | } |
| 505 | @ </item> |
| 506 | free(zTechnoteId); |
| 507 | blob_reset(&contentHtml); |
| 508 | free(zDate); |
| 509 | free(zSuffix); |
| 510 | nLine++; |
| @@ -658,14 +691,13 @@ | |
| 691 | char *zSuffix = 0; |
| 692 | char *zDate; |
| 693 | int nChild = db_column_int(&q, 6); |
| 694 | int nParent = db_column_int(&q, 7); |
| 695 | const char *zTagList = db_column_text(&q, 8); |
| 696 | char *zTechnoteId = 0; |
| 697 | Blob contentHtml = BLOB_INITIALIZER; |
| 698 | int bHasContent = 0; |
| 699 | time_t ts; |
| 700 | |
| 701 | if( zTagList && zTagList[0]==0 ) zTagList = 0; |
| 702 | ts = (time_t)((db_column_double(&q,2) - 2440587.5)*86400.0); |
| 703 | zDate = cgi_rfc822_datestamp(ts); |
| @@ -689,63 +721,27 @@ | |
| 721 | |
| 722 | if( zTagList ){ |
| 723 | zSuffix = mprintf(" (tags: %s)", zTagList); |
| 724 | } |
| 725 | |
| 726 | bHasContent = rss_render_item_html(&contentHtml, &zTechnoteId, rid, zEType, |
| 727 | blob_str(&base), blob_str(&top), 0); |
| 728 | fossil_print("<item>"); |
| 729 | fossil_print("<title>%s%h%h</title>\n", zPrefix, zCom, zSuffix); |
| 730 | if( zTechnoteId!=0 ){ |
| 731 | fossil_print("<link>%s/info/%s</link>\n", zBaseURL, zTechnoteId); |
| 732 | }else{ |
| 733 | fossil_print("<link>%s/info/%s</link>\n", zBaseURL, zId); |
| 734 | } |
| 735 | fossil_print("<description>%s%h%h</description>\n", zPrefix, zCom, zSuffix); |
| 736 | fossil_print("<pubDate>%s</pubDate>\n", zDate); |
| 737 | fossil_print("<dc:creator>%h</dc:creator>\n", zAuthor); |
| 738 | fossil_print("<guid>%s/info/%s</guid>\n", g.zBaseURL, zId); |
| 739 | if( bHasContent ){ |
| 740 | rss_cli_emit_html_content(&contentHtml); |
| 741 | } |
| 742 | fossil_print("</item>\n"); |
| 743 | free(zTechnoteId); |
| 744 | blob_reset(&contentHtml); |
| 745 | free(zDate); |
| 746 | free(zSuffix); |
| 747 | nLine++; |
| 748 |