0000: 23 21 2f 75 73 72 2f 62 69 6e 2f 70 68 70 2d 63 #!/usr/bin/php-c
0010: 67 69 20 2d 64 63 67 69 2e 66 6f 72 63 65 5f 72 gi -dcgi.force_r
0020: 65 64 69 72 65 63 74 3d 30 0a 3c 3f 70 68 70 0a edirect=0.<?php.
0030: 23 20 65 6e 63 6f 64 69 6e 67 3a 20 75 74 66 2d # encoding: utf-
0040: 38 0a 23 20 61 70 69 3a 20 63 67 69 0a 23 20 74 8.# api: cgi.# t
0050: 79 70 65 3a 20 73 74 6f 72 65 0a 23 20 63 61 74 ype: store.# cat
0060: 65 67 6f 72 79 3a 20 74 65 6d 70 6c 61 74 65 0a egory: template.
0070: 23 20 74 69 74 6c 65 3a 20 66 78 5f 6d 65 74 61 # title: fx_meta
0080: 20 63 61 63 68 65 0a 23 20 64 65 73 63 72 69 70 cache.# descrip
0090: 74 69 6f 6e 3a 20 50 72 65 70 61 72 65 20 74 77 tion: Prepare tw
00a0: 69 74 74 65 72 20 74 61 67 73 20 66 6f 72 20 77 itter tags for w
00b0: 69 6b 69 20 2b 20 64 6f 63 20 70 61 67 65 73 0a iki + doc pages.
00c0: 23 20 76 65 72 73 69 6f 6e 3a 20 30 2e 36 0a 23 # version: 0.6.#
00d0: 20 73 74 61 74 65 3a 20 61 6c 70 68 61 0a 23 20 state: alpha.#
00e0: 63 6f 6e 66 69 67 3a 0a 23 20 20 20 20 7b 20 6e config:.# { n
00f0: 61 6d 65 3a 20 70 72 6f 6a 65 63 74 2d 74 77 69 ame: project-twi
0100: 74 74 65 72 2c 20 74 79 70 65 3a 20 73 74 72 2c tter, type: str,
0110: 20 76 61 6c 75 65 3a 20 22 22 2c 20 64 65 73 63 value: "", desc
0120: 72 69 70 74 69 6f 6e 3a 20 22 54 77 69 74 74 65 ription: "Twitte
0130: 72 20 68 61 6e 64 6c 65 20 66 6f 72 20 70 72 6f r handle for pro
0140: 6a 65 63 74 20 28 65 2e 67 2e 20 40 73 71 6c 69 ject (e.g. @sqli
0150: 74 65 31 29 22 20 7d 0a 23 20 61 63 63 65 73 73 te1)" }.# access
0160: 3a 20 61 64 6d 69 6e 0a 23 0a 23 20 43 72 61 66 : admin.#.# Craf
0170: 74 73 20 61 20 60 66 78 5f 6d 65 74 61 60 20 64 ts a `fx_meta` d
0180: 61 74 61 62 61 73 65 20 74 61 62 6c 65 20 74 6f atabase table to
0190: 20 70 72 65 70 61 72 65 20 74 77 69 74 74 65 72 prepare twitter
01a0: 20 70 72 65 76 69 65 77 73 0a 23 20 61 6e 64 20 previews.# and
01b0: 69 6d 61 67 65 20 6c 69 6e 6b 73 2c 20 6f 72 20 image links, or
01c0: 6f 74 68 65 72 20 3c 6d 65 74 61 3e 20 61 6e 64 other <meta> and
01d0: 20 3c 6c 69 6e 6b 3e 20 66 69 65 6c 64 73 2e 0a <link> fields..
01e0: 23 20 57 68 69 63 68 20 63 61 6e 20 74 68 65 6e # Which can then
01f0: 20 62 65 20 65 6d 62 65 64 64 65 64 20 69 6e 74 be embedded int
0200: 6f 20 74 68 65 20 68 65 61 64 65 72 20 76 69 61 o the header via
0210: 3a 0a 23 0a 23 20 20 20 3c 74 68 31 3e 20 20 63 :.#.# <th1> c
0220: 61 74 63 68 20 7b 20 71 75 65 72 79 20 7b 53 45 atch { query {SE
0230: 4c 45 43 54 20 6d 65 74 61 20 46 52 4f 4d 20 66 LECT meta FROM f
0240: 78 5f 6d 65 74 61 20 57 48 45 52 45 20 6e 61 6d x_meta WHERE nam
0250: 65 20 3d 20 24 63 75 72 72 65 6e 74 5f 70 61 67 e = $current_pag
0260: 65 7d 20 7b 20 68 74 6d 6c 20 24 6d 65 74 61 20 e} { html $meta
0270: 7d 20 7d 20 20 3c 2f 74 68 31 3e 0a 23 0a 23 20 } } </th1>.#.#
0280: c2 b7 20 53 68 6f 75 6c 64 20 62 65 20 75 73 65 ยท Should be use
0290: 61 62 6c 65 20 61 73 20 65 78 74 72 6f 6f 74 2f able as extroot/
02a0: 20 68 6f 6f 6b 2e 0a 23 20 c2 b7 20 41 73 20 63 hook..# ยท As c
02b0: 72 6f 6e 20 73 63 72 69 70 74 20 69 74 20 77 6f ron script it wo
02c0: 75 6c 64 20 72 65 71 75 69 72 65 20 73 75 70 70 uld require supp
02d0: 6c 79 69 6e 67 20 74 68 65 20 72 65 70 6f 73 69 lying the reposi
02e0: 74 6f 72 79 20 66 69 6c 65 2c 20 61 6e 64 20 73 tory file, and s
02f0: 65 74 74 69 6e 67 0a 23 20 20 20 53 45 52 56 45 etting.# SERVE
0300: 52 5f 4e 41 4d 45 20 61 6e 64 20 46 4f 53 53 49 R_NAME and FOSSI
0310: 4c 5f 55 52 49 20 65 6e 76 20 76 61 72 73 2e 0a L_URI env vars..
0320: 23 20 c2 b7 20 50 6f 73 73 69 62 6c 79 20 73 68 # ยท Possibly sh
0330: 6f 75 6c 64 20 61 64 61 70 74 20 74 77 69 74 74 ould adapt twitt
0340: 65 72 3a 73 69 74 65 20 28 6f 72 20 72 65 6d 6f er:site (or remo
0350: 76 65 20 69 66 20 74 68 65 20 73 6b 69 6e 20 61 ve if the skin a
0360: 6c 72 65 61 64 79 20 63 6f 6e 74 61 69 6e 73 20 lready contains
0370: 69 74 29 0a 23 0a 23 20 46 69 6c 65 20 6c 69 6e it).#.# File lin
0380: 6b 73 20 73 68 6f 75 6c 64 6e 27 74 20 62 65 20 ks shouldn't be
0390: 67 65 6e 65 72 61 74 65 64 20 73 74 61 74 69 63 generated static
03a0: 61 6c 6c 79 20 74 68 6f 75 67 68 2e 20 54 68 65 ally though. The
03b0: 72 65 27 73 20 60 66 69 6c 65 5f 6c 69 6e 6b 2e re's `file_link.
03c0: 74 68 31 60 20 6e 6f 77 0a 23 20 61 73 20 61 75 th1` now.# as au
03d0: 78 69 6c 69 61 72 79 20 66 65 61 74 75 72 65 2e xiliary feature.
03e0: 0a 23 20 20 20 3c 74 68 31 3e 20 63 61 74 63 68 .# <th1> catch
03f0: 20 7b 20 66 69 6c 65 5f 6c 69 6e 6b 20 7d 20 3c { file_link } <
0400: 2f 74 68 31 3e 0a 23 20 57 69 6c 6c 20 6f 75 74 /th1>.# Will out
0410: 70 75 74 20 74 68 65 20 76 63 73 2d 72 61 77 20 put the vcs-raw
0420: 6c 69 6e 6b 73 20 69 6e 73 74 65 61 64 2e 0a 23 links instead..#
0430: 0a 0a 0a 23 2d 2d 20 63 6f 6e 66 69 67 0a 65 72 ...#-- config.er
0440: 72 6f 72 5f 72 65 70 6f 72 74 69 6e 67 28 45 5f ror_reporting(E_
0450: 41 4c 4c 29 3b 0a 69 6e 69 5f 73 65 74 28 22 64 ALL);.ini_set("d
0460: 69 73 70 6c 61 79 5f 65 72 72 6f 72 73 22 2c 20 isplay_errors",
0470: 31 29 3b 0a 64 65 66 69 6e 65 28 22 50 52 4f 4a 1);.define("PROJ
0480: 45 43 54 5f 54 57 49 54 54 45 52 22 2c 20 22 73 ECT_TWITTER", "s
0490: 71 6c 69 74 65 31 22 29 3b 20 20 23 20 69 66 20 qlite1"); # if
04a0: 6e 6f 74 20 76 69 61 20 65 78 74 72 61 20 63 6f not via extra co
04b0: 6e 66 69 67 0a 69 6e 63 6c 75 64 65 28 22 2e 2f nfig.include("./
04c0: 66 6f 73 73 69 6c 5f 63 6f 6d 6d 6f 6e 2e 70 68 fossil_common.ph
04d0: 70 22 29 3b 0a 0a 23 2d 2d 20 63 6c 69 20 6f 72 p");..#-- cli or
04e0: 20 61 64 6d 69 6e 20 75 73 61 67 65 0a 69 66 20 admin usage.if
04f0: 28 21 65 6d 70 74 79 28 24 5f 53 45 52 56 45 52 (!empty($_SERVER
0500: 5b 22 61 72 67 76 22 5d 5b 31 5d 29 29 20 7b 0a ["argv"][1])) {.
0510: 20 20 20 20 24 5f 53 45 52 56 45 52 5b 22 46 4f $_SERVER["FO
0520: 53 53 49 4c 5f 52 45 50 4f 53 49 54 4f 52 59 22 SSIL_REPOSITORY"
0530: 5d 20 3d 20 24 5f 53 45 52 56 45 52 5b 22 61 72 ] = $_SERVER["ar
0540: 67 76 22 5d 5b 31 5d 3b 0a 7d 0a 65 6c 73 65 69 gv"][1];.}.elsei
0550: 66 20 28 21 69 73 5f 61 64 6d 69 6e 28 29 29 20 f (!is_admin())
0560: 7b 0a 20 20 20 20 64 69 65 28 22 52 75 6e 20 61 {. die("Run a
0570: 73 20 63 72 6f 6e 2c 20 6f 72 20 61 73 20 61 64 s cron, or as ad
0580: 6d 69 6e 22 29 3b 0a 7d 0a 70 75 74 65 6e 76 28 min");.}.putenv(
0590: 22 47 41 54 45 57 41 59 5f 49 4e 54 45 52 46 41 "GATEWAY_INTERFA
05a0: 43 45 3d 22 29 3b 0a 70 75 74 65 6e 76 28 22 52 CE=");.putenv("R
05b0: 45 51 55 45 53 54 5f 55 52 49 3d 22 29 3b 0a 70 EQUEST_URI=");.p
05c0: 75 74 65 6e 76 28 22 53 43 52 49 50 54 5f 46 49 utenv("SCRIPT_FI
05d0: 4c 45 4e 41 4d 45 3d 22 29 3b 0a 69 6e 69 5f 73 LENAME=");.ini_s
05e0: 65 74 28 22 64 69 73 70 6c 61 79 5f 65 72 72 6f et("display_erro
05f0: 72 73 22 2c 20 31 29 3b 0a 0a 0a 0a 23 20 49 4e rs", 1);....# IN
0600: 53 45 52 54 0a 66 75 6e 63 74 69 6f 6e 20 69 6e SERT.function in
0610: 73 65 72 74 5f 6d 65 74 61 28 24 6e 61 6d 65 2c sert_meta($name,
0620: 20 24 6d 65 74 61 29 20 7b 0a 20 20 20 64 62 28 $meta) {. db(
0630: 0a 20 20 20 20 20 20 20 20 22 49 4e 53 45 52 54 . "INSERT
0640: 20 49 4e 54 4f 20 66 78 5f 6d 65 74 61 20 28 60 INTO fx_meta (`
0650: 6e 61 6d 65 60 2c 20 60 6d 65 74 61 60 29 20 56 name`, `meta`) V
0660: 41 4c 55 45 53 20 28 3f 2c 20 3f 29 3b 22 2c 0a ALUES (?, ?);",.
0670: 20 20 20 20 20 20 20 20 5b 24 6e 61 6d 65 2c 20 [$name,
0680: 24 6d 65 74 61 5d 0a 20 20 20 20 29 3b 0a 7d 0a $meta]. );.}.
0690: 0a 23 2d 2d 20 69 6e 69 74 0a 64 62 28 22 43 52 .#-- init.db("CR
06a0: 45 41 54 45 20 54 41 42 4c 45 20 49 46 20 4e 4f EATE TABLE IF NO
06b0: 54 20 45 58 49 53 54 53 20 66 78 5f 6d 65 74 61 T EXISTS fx_meta
06c0: 20 28 6e 61 6d 65 20 54 45 58 54 2c 20 6d 65 74 (name TEXT, met
06d0: 61 20 54 45 58 54 29 22 29 3b 0a 64 62 28 22 44 a TEXT)");.db("D
06e0: 45 4c 45 54 45 20 46 52 4f 4d 20 66 78 5f 6d 65 ELETE FROM fx_me
06f0: 74 61 22 29 3b 0a 77 69 6b 69 5f 70 61 67 65 73 ta");.wiki_pages
0700: 28 29 3b 0a 64 6f 63 5f 70 61 67 65 73 28 29 3b ();.doc_pages();
0710: 0a 77 69 6b 69 5f 65 76 65 6e 74 28 29 3b 0a 0a .wiki_event();..
0720: 0a 23 2d 2d 20 6c 6f 6f 70 20 74 68 72 6f 75 67 .#-- loop throug
0730: 68 20 70 61 67 65 73 0a 66 75 6e 63 74 69 6f 6e h pages.function
0740: 20 77 69 6b 69 5f 70 61 67 65 73 28 24 74 61 67 wiki_pages($tag
0750: 70 72 65 66 69 78 3d 22 77 69 6b 69 2d 22 2c 20 prefix="wiki-",
0760: 24 63 6c 69 5f 61 72 67 73 3d 22 22 2c 20 24 75 $cli_args="", $u
0770: 72 6c 3d 22 77 69 6b 69 3f 6e 61 6d 65 3d 22 2c rl="wiki?name=",
0780: 20 24 6c 6f 6e 67 3d 30 29 20 7b 0a 20 20 20 20 $long=0) {.
0790: 66 6f 72 65 61 63 68 20 28 64 62 28 22 53 45 4c foreach (db("SEL
07a0: 45 43 54 20 74 61 67 6e 61 6d 65 20 41 53 20 6e ECT tagname AS n
07b0: 61 6d 65 20 46 52 4f 4d 20 74 61 67 20 57 48 45 ame FROM tag WHE
07c0: 52 45 20 74 61 67 6e 61 6d 65 20 4c 49 4b 45 20 RE tagname LIKE
07d0: 27 24 74 61 67 70 72 65 66 69 78 25 27 3b 22 29 '$tagprefix%';")
07e0: 20 61 73 20 24 70 61 67 65 29 20 7b 0a 20 20 20 as $page) {.
07f0: 20 20 20 20 20 24 70 61 67 65 20 3d 20 73 75 62 $page = sub
0800: 73 74 72 28 24 70 61 67 65 5b 22 6e 61 6d 65 22 str($page["name"
0810: 5d 2c 20 73 74 72 70 6f 73 28 24 70 61 67 65 5b ], strpos($page[
0820: 22 6e 61 6d 65 22 5d 2c 20 22 2d 22 29 20 2b 20 "name"], "-") +
0830: 31 29 3b 0a 20 20 20 20 20 20 20 20 70 72 69 6e 1);. prin
0840: 74 20 22 3c 6c 69 3e 24 70 61 67 65 5c 6e 22 3b t "<li>$page\n";
0850: 0a 20 20 20 20 20 20 20 20 24 71 20 3d 20 22 65 . $q = "e
0860: 73 63 61 70 65 73 68 65 6c 6c 61 72 67 22 3b 0a scapeshellarg";.
0870: 20 20 20 20 20 20 20 20 24 68 74 6d 6c 20 3d 20 $html =
0880: 73 68 65 6c 6c 5f 65 78 65 63 28 22 66 6f 73 73 shell_exec("foss
0890: 69 6c 20 2d 2d 6e 6f 63 67 69 20 77 69 6b 69 20 il --nocgi wiki
08a0: 65 78 70 6f 72 74 20 24 63 6c 69 5f 61 72 67 73 export $cli_args
08b0: 20 2d 2d 68 74 6d 6c 20 7b 24 71 28 24 70 61 67 --html {$q($pag
08c0: 65 29 7d 20 2d 52 20 7b 24 71 28 24 5f 53 45 52 e)} -R {$q($_SER
08d0: 56 45 52 5b 27 46 4f 53 53 49 4c 5f 52 45 50 4f VER['FOSSIL_REPO
08e0: 53 49 54 4f 52 59 27 5d 29 7d 20 32 3e 26 31 22 SITORY'])} 2>&1"
08f0: 29 3b 0a 20 20 20 20 20 20 20 20 69 6e 73 65 72 );. inser
0900: 74 5f 6d 65 74 61 28 0a 20 20 20 20 20 20 20 20 t_meta(.
0910: 20 20 20 20 24 75 72 6c 20 2e 20 24 70 61 67 65 $url . $page
0920: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 68 74 ,. ht
0930: 6d 6c 5f 6d 65 74 61 28 24 70 61 67 65 2c 20 24 ml_meta($page, $
0940: 68 74 6d 6c 2c 20 24 6c 6f 6e 67 29 0a 20 20 20 html, $long).
0950: 20 20 20 20 20 29 3b 0a 20 20 20 20 7d 0a 7d 0a );. }.}.
0960: 23 2d 2d 20 74 65 63 68 6e 6f 74 65 73 0a 66 75 #-- technotes.fu
0970: 6e 63 74 69 6f 6e 20 77 69 6b 69 5f 65 76 65 6e nction wiki_even
0980: 74 28 29 20 7b 0a 20 20 20 20 77 69 6b 69 5f 70 t() {. wiki_p
0990: 61 67 65 73 28 22 65 76 65 6e 74 2d 22 2c 20 22 ages("event-", "
09a0: 2d 2d 74 65 63 68 6e 6f 74 65 22 2c 20 22 74 65 --technote", "te
09b0: 63 68 6e 6f 74 65 2f 22 2c 20 31 29 3b 0a 7d 0a chnote/", 1);.}.
09c0: 0a 23 2d 2d 20 73 63 61 6e 20 2a 2e 6d 64 2f 77 .#-- scan *.md/w
09d0: 69 6b 69 20 66 69 6c 65 73 0a 66 75 6e 63 74 69 iki files.functi
09e0: 6f 6e 20 64 6f 63 5f 70 61 67 65 73 28 29 20 7b on doc_pages() {
09f0: 0a 20 20 20 20 66 6f 72 65 61 63 68 20 28 64 62 . foreach (db
0a00: 28 22 53 45 4c 45 43 54 20 6e 61 6d 65 20 46 52 ("SELECT name FR
0a10: 4f 4d 20 66 69 6c 65 6e 61 6d 65 22 29 20 61 73 OM filename") as
0a20: 20 24 70 61 67 65 29 20 7b 0a 20 20 20 20 20 20 $page) {.
0a30: 20 20 24 66 6e 20 3d 20 24 70 61 67 65 5b 22 6e $fn = $page["n
0a40: 61 6d 65 22 5d 3b 0a 20 20 20 20 20 20 20 20 69 ame"];. i
0a50: 66 20 28 21 70 72 65 67 5f 6d 61 74 63 68 28 22 f (!preg_match("
0a60: 2f 5c 2e 28 6d 64 7c 77 69 6b 69 29 24 2f 22 2c /\.(md|wiki)$/",
0a70: 20 24 66 6e 29 29 20 7b 0a 20 20 20 20 20 20 20 $fn)) {.
0a80: 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 continue;.
0a90: 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 }.
0aa0: 20 70 72 69 6e 74 20 22 3c 6c 69 3e 24 66 6e 5c print "<li>$fn\
0ab0: 6e 22 3b 0a 20 20 20 20 20 20 20 20 24 71 20 3d n";. $q =
0ac0: 20 22 65 73 63 61 70 65 73 68 65 6c 6c 61 72 67 "escapeshellarg
0ad0: 22 3b 0a 20 20 20 20 20 20 20 20 24 6d 64 20 3d ";. $md =
0ae0: 20 73 68 65 6c 6c 5f 65 78 65 63 28 22 66 6f 73 shell_exec("fos
0af0: 73 69 6c 20 2d 2d 6e 6f 63 67 69 20 63 61 74 20 sil --nocgi cat
0b00: 7b 24 71 28 24 66 6e 29 7d 20 2d 52 20 7b 24 71 {$q($fn)} -R {$q
0b10: 28 24 5f 53 45 52 56 45 52 5b 27 46 4f 53 53 49 ($_SERVER['FOSSI
0b20: 4c 5f 52 45 50 4f 53 49 54 4f 52 59 27 5d 29 7d L_REPOSITORY'])}
0b30: 20 32 3e 26 31 22 29 3b 0a 20 20 20 20 20 20 20 2>&1");.
0b40: 20 69 66 20 28 21 24 6d 64 29 20 7b 0a 20 20 20 if (!$md) {.
0b50: 20 20 20 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 continu
0b60: 65 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 e;. }.
0b70: 20 20 20 20 20 24 6d 65 74 61 20 3d 20 68 74 6d $meta = htm
0b80: 6c 5f 6d 65 74 61 28 24 66 6e 2c 20 24 6d 64 29 l_meta($fn, $md)
0b90: 3b 0a 20 20 20 20 20 20 20 20 69 6e 73 65 72 74 ;. insert
0ba0: 5f 6d 65 74 61 28 22 64 6f 63 2f 74 72 75 6e 6b _meta("doc/trunk
0bb0: 2f 24 66 6e 22 2c 20 24 6d 65 74 61 29 3b 0a 20 /$fn", $meta);.
0bc0: 20 20 20 20 20 20 20 69 6e 73 65 72 74 5f 6d 65 insert_me
0bd0: 74 61 28 22 64 6f 63 2f 74 69 70 2f 24 66 6e 22 ta("doc/tip/$fn"
0be0: 2c 20 24 6d 65 74 61 29 3b 0a 20 20 20 20 7d 0a , $meta);. }.
0bf0: 7d 0a 0a 23 20 3c 6d 65 74 61 3e 20 61 6e 64 20 }..# <meta> and
0c00: 3c 6c 69 6e 6b 3e 73 20 66 6f 72 20 61 20 77 69 <link>s for a wi
0c10: 6b 69 20 70 61 67 65 0a 23 20 20 c2 b7 20 77 69 ki page.# ยท wi
0c20: 6b 69 3f 6e 61 6d 65 3d 50 61 67 65 4e 61 6d 65 ki?name=PageName
0c30: 0a 66 75 6e 63 74 69 6f 6e 20 68 74 6d 6c 5f 6d .function html_m
0c40: 65 74 61 28 24 6e 61 6d 65 2c 20 24 68 74 6d 6c eta($name, $html
0c50: 2c 20 24 6c 6f 6e 67 3d 30 29 20 7b 0a 0a 20 20 , $long=0) {..
0c60: 20 20 23 20 63 6c 65 61 6e 75 70 0a 20 20 20 20 # cleanup.
0c70: 24 68 74 6d 6c 20 3d 20 70 72 65 67 5f 72 65 70 $html = preg_rep
0c80: 6c 61 63 65 28 22 7e 3c 74 61 62 6c 65 2e 2b 3f lace("~<table.+?
0c90: 3c 2f 74 61 62 6c 65 3e 7e 73 22 2c 20 22 22 2c </table>~s", "",
0ca0: 20 24 68 74 6d 6c 29 3b 0a 20 20 20 20 24 74 65 $html);. $te
0cb0: 78 74 20 3d 20 74 72 69 6d 28 70 72 65 67 5f 72 xt = trim(preg_r
0cc0: 65 70 6c 61 63 65 28 22 7e 5c 73 2b 7e 22 2c 20 eplace("~\s+~",
0cd0: 22 20 22 2c 20 73 74 72 69 70 5f 74 61 67 73 28 " ", strip_tags(
0ce0: 24 68 74 6d 6c 29 29 29 3b 0a 20 20 20 20 24 64 $html)));. $d
0cf0: 65 73 63 20 3d 20 73 75 62 73 74 72 28 24 74 65 esc = substr($te
0d00: 78 74 2c 20 30 2c 20 32 35 30 29 3b 0a 20 20 20 xt, 0, 250);.
0d10: 20 0a 20 20 20 20 23 20 70 72 65 70 61 72 65 20 . # prepare
0d20: 74 61 67 73 0a 20 20 20 20 24 74 77 69 74 74 65 tags. $twitte
0d30: 72 20 3d 20 74 72 69 6d 28 67 65 74 5f 63 6f 6e r = trim(get_con
0d40: 66 69 67 28 22 70 72 6f 6a 65 63 74 2d 74 77 69 fig("project-twi
0d50: 74 74 65 72 22 2c 20 50 52 4f 4a 45 43 54 5f 54 tter", PROJECT_T
0d60: 57 49 54 54 45 52 29 2c 20 22 40 22 29 3b 0a 20 WITTER), "@");.
0d70: 20 20 20 24 68 20 3d 20 22 68 22 3b 0a 20 20 20 $h = "h";.
0d80: 20 69 66 20 28 24 6c 6f 6e 67 20 26 26 20 70 72 if ($long && pr
0d90: 65 67 5f 6d 61 74 63 68 28 22 7e 3c 68 5c 64 3e eg_match("~<h\d>
0da0: 28 2e 2b 29 3c 2f 68 5c 64 3e 7e 22 2c 20 24 68 (.+)</h\d>~", $h
0db0: 74 6d 6c 2c 20 24 75 75 29 29 20 7b 0a 20 20 20 tml, $uu)) {.
0dc0: 20 20 20 20 20 24 6e 61 6d 65 20 3d 20 24 75 75 $name = $uu
0dd0: 5b 31 5d 3b 20 20 2f 2f 20 74 65 63 68 6e 6f 74 [1]; // technot
0de0: 65 20 70 61 67 65 73 20 72 65 71 75 69 72 65 20 e pages require
0df0: 61 20 68 65 61 64 6c 69 6e 65 0a 20 20 20 20 7d a headline. }
0e00: 0a 20 20 20 20 0a 20 20 20 20 23 20 63 68 65 63 . . # chec
0e10: 6b 20 66 6f 72 20 69 6d 61 67 65 0a 20 20 20 20 k for image.
0e20: 69 66 20 28 70 72 65 67 5f 6d 61 74 63 68 28 22 if (preg_match("
0e30: 7e 3c 69 6d 67 5b 5e 3e 5d 2b 20 73 72 63 3d 5b ~<img[^>]+ src=[
0e40: 5c 22 27 5d 3f 20 28 5b 5e 5c 22 27 5c 73 3e 5d \"']? ([^\"'\s>]
0e50: 2b 29 7e 78 22 2c 20 24 68 74 6d 6c 2c 20 24 75 +)~x", $html, $u
0e60: 75 29 20 7c 7c 20 70 72 65 67 5f 6d 61 74 63 68 u) || preg_match
0e70: 28 22 7e 28 72 61 77 2f 5c 77 2b 29 20 5c 3f 6d ("~(raw/\w+) \?m
0e80: 3d 69 6d 61 67 65 2f 7e 78 22 2c 20 24 68 74 6d =image/~x", $htm
0e90: 6c 2c 20 24 75 75 29 20 6f 72 20 24 75 75 3d 5b l, $uu) or $uu=[
0ea0: 22 22 2c 22 6c 6f 67 6f 22 5d 29 20 7b 0a 20 20 "","logo"]) {.
0eb0: 20 20 20 20 20 20 24 69 6d 67 20 3d 20 24 75 75 $img = $uu
0ec0: 5b 31 5d 3b 0a 20 20 20 20 20 20 20 20 69 66 20 [1];. if
0ed0: 28 73 74 72 73 74 72 28 24 69 6d 67 2c 20 22 3a (strstr($img, ":
0ee0: 2f 2f 22 29 29 20 7b 0a 20 20 20 20 20 20 20 20 //")) {.
0ef0: 7d 0a 20 20 20 20 20 20 20 20 65 6c 73 65 69 66 }. elseif
0f00: 20 28 70 72 65 67 5f 6d 61 74 63 68 28 22 7e 72 (preg_match("~r
0f10: 61 77 2f 7c 64 6f 63 2f 7c 5e 6c 6f 67 6f 24 7e aw/|doc/|^logo$~
0f20: 22 2c 20 24 69 6d 67 29 29 20 7b 0a 20 20 20 20 ", $img)) {.
0f30: 20 20 20 20 20 20 20 20 24 69 6d 67 20 3d 20 24 $img = $
0f40: 5f 53 45 52 56 45 52 5b 22 46 4f 53 53 49 4c 5f _SERVER["FOSSIL_
0f50: 53 45 4c 46 22 5d 20 2e 20 24 69 6d 67 3b 0a 20 SELF"] . $img;.
0f60: 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 }.
0f70: 20 65 6c 73 65 69 66 20 28 24 69 6d 67 5b 30 5d elseif ($img[0]
0f80: 20 3d 3d 20 22 2f 22 29 20 7b 0a 20 20 20 20 20 == "/") {.
0f90: 20 20 20 20 20 20 20 24 69 6d 67 20 3d 20 22 68 $img = "h
0fa0: 74 74 70 73 3a 2f 2f 24 5f 53 45 52 56 45 52 5b ttps://$_SERVER[
0fb0: 53 45 52 56 45 52 5f 4e 41 4d 45 5d 24 69 6d 67 SERVER_NAME]$img
0fc0: 22 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 ";. }.
0fd0: 20 20 20 20 20 24 73 75 6d 6d 61 72 79 20 3d 20 $summary =
0fe0: 24 6c 6f 6e 67 20 3f 20 22 73 75 6d 6d 61 72 79 $long ? "summary
0ff0: 5f 6c 61 72 67 65 5f 69 6d 61 67 65 22 20 3a 20 _large_image" :
1000: 22 73 75 6d 6d 61 72 79 22 3b 0a 20 20 20 20 20 "summary";.
1010: 20 20 20 24 6d 65 74 61 20 3d 20 3c 3c 3c 45 4f $meta = <<<EO
1020: 46 0a 20 20 3c 6d 65 74 61 20 6e 61 6d 65 3d 22 F. <meta name="
1030: 74 77 69 74 74 65 72 3a 63 61 72 64 22 20 63 6f twitter:card" co
1040: 6e 74 65 6e 74 3d 22 24 73 75 6d 6d 61 72 79 22 ntent="$summary"
1050: 3e 0a 20 20 3c 6d 65 74 61 20 6e 61 6d 65 3d 22 >. <meta name="
1060: 74 77 69 74 74 65 72 3a 73 69 74 65 22 20 63 6f twitter:site" co
1070: 6e 74 65 6e 74 3d 22 40 24 74 77 69 74 74 65 72 ntent="@$twitter
1080: 22 3e 0a 20 20 3c 6d 65 74 61 20 6e 61 6d 65 3d ">. <meta name=
1090: 22 74 77 69 74 74 65 72 3a 63 72 65 61 74 6f 72 "twitter:creator
10a0: 22 20 63 6f 6e 74 65 6e 74 3d 22 40 24 74 77 69 " content="@$twi
10b0: 74 74 65 72 22 3e 0a 20 20 3c 6d 65 74 61 20 6e tter">. <meta n
10c0: 61 6d 65 3d 22 74 77 69 74 74 65 72 3a 74 69 74 ame="twitter:tit
10d0: 6c 65 22 20 63 6f 6e 74 65 6e 74 3d 22 7b 24 68 le" content="{$h
10e0: 28 24 6e 61 6d 65 29 7d 22 3e 0a 20 20 3c 6d 65 ($name)}">. <me
10f0: 74 61 20 6e 61 6d 65 3d 22 74 77 69 74 74 65 72 ta name="twitter
1100: 3a 64 65 73 63 72 69 70 74 69 6f 6e 22 20 63 6f :description" co
1110: 6e 74 65 6e 74 3d 22 7b 24 68 28 24 64 65 73 63 ntent="{$h($desc
1120: 29 7d 22 3e 0a 20 20 3c 6d 65 74 61 20 6e 61 6d )}">. <meta nam
1130: 65 3d 22 74 77 69 74 74 65 72 3a 69 6d 61 67 65 e="twitter:image
1140: 22 20 63 6f 6e 74 65 6e 74 3d 22 7b 24 68 28 24 " content="{$h($
1150: 69 6d 67 29 7d 22 3e 0a 20 20 3c 6d 65 74 61 20 img)}">. <meta
1160: 6e 61 6d 65 3d 22 74 77 69 74 74 65 72 3a 69 6d name="twitter:im
1170: 61 67 65 3a 73 72 63 22 20 63 6f 6e 74 65 6e 74 age:src" content
1180: 3d 22 7b 24 68 28 24 69 6d 67 29 7d 22 3e 0a 45 ="{$h($img)}">.E
1190: 4f 46 3b 0a 20 20 20 20 20 20 20 20 23 20 63 6f OF;. # co
11a0: 75 6c 64 20 61 64 64 20 46 42 20 28 6f 67 3a 69 uld add FB (og:i
11b0: 6d 61 67 65 2c 20 6f 67 3a 74 69 74 6c 65 2c 20 mage, og:title,
11c0: 6f 67 3a 64 65 73 63 72 69 70 74 69 6f 6e 2c 20 og:description,
11d0: 6f 67 3a 75 72 6c 29 20 61 73 20 77 65 6c 6c 0a og:url) as well.
11e0: 20 20 20 20 7d 0a 20 20 20 20 65 6c 73 65 20 7b }. else {
11f0: 0a 20 20 20 20 20 20 20 20 24 6d 65 74 61 20 3d . $meta =
1200: 20 22 20 20 3c 6d 65 74 61 20 6e 61 6d 65 3d 64 " <meta name=d
1210: 65 73 63 72 69 70 74 69 6f 6e 20 63 6f 6e 74 65 escription conte
1220: 6e 74 3d 5c 22 7b 24 68 28 24 64 65 73 63 29 7d nt=\"{$h($desc)}
1230: 5c 22 3e 5c 6e 22 3b 0a 20 20 20 20 7d 0a 0a 20 \">\n";. }..
1240: 20 20 20 24 6d 65 74 61 20 3d 20 70 72 65 67 5f $meta = preg_
1250: 72 65 70 6c 61 63 65 28 22 7e 28 3f 3c 21 3a 29 replace("~(?<!:)
1260: 2f 2f 2b 7e 22 2c 20 22 2f 22 2c 20 24 6d 65 74 //+~", "/", $met
1270: 61 29 3b 20 2f 2f 20 72 65 70 6c 61 63 65 20 61 a); // replace a
1280: 6e 79 20 64 6f 75 62 6c 65 20 2f 2f 20 69 6e 20 ny double // in
1290: 70 61 74 68 73 0a 20 20 20 20 72 65 74 75 72 6e paths. return
12a0: 20 24 6d 65 74 61 3b 0a 7d 0a 0a $meta;.}..