3 . "$_EXEC/cgilite/cgilite.sh"
7 from='1'; to='$'; rev=''; items='$'
9 while [ $# -gt 0 ]; do case $1 in
10 --from) from="$2"; shift 2;;
11 from=*) from="${1#*=}"; shift 1;;
12 --to) to="$2"; shift 2;;
13 to=*) to="${1#*=}"; shift 1;;
14 --items) items="$2"; shift 2;;
15 items=*) items="${1#*=}"; shift 1;;
16 --rev|--reverse) rev="-r"; shift 1;;
17 *) page="$1"; shift 1;;
20 if ! printf %s\\n "$from" |grep -qEx '[0-9]+|/([^/\\]|\\/|\\.)*/'; then
21 debug 'Include macro invalid argument: "from"'
24 if ! printf %s\\n "$to" |grep -qEx '[0-9]+|/([^/\\]|\\/|\\.)*/'; then
25 debug 'Include macro Invalid argument: "to"'
28 if ! printf %s\\n "$items" |grep -qEx '\$|[0-9]+'; then
29 debug 'Include macro Invalid argument: "items"'
37 page="$(page_abs "$glob")"
38 acl_read "$page" || continue
39 mdfile="$(mdfile "$page")" || continue
40 hglob="$(HTML "$glob")"
41 refpfx="$(printf %s\\n "$hglob" |sed 's;[\;&\;];\\&;g')"
42 printf '<div class="macro include">
43 <a class="include link" href="%s">%s</a>
44 <article class="include" id="include_%s">' \
45 "${hglob}" "${hglob}" "${hglob}"
46 ( # PATH_INFO may be used by macros in the included page
47 export PATH_INFO="$page"
49 sed -n "${from},${to}p" <"$mdfile" \
53 s;(<[^>]+ )(href|src)="([^"]+://[^"]*|[mM][aA][iI][lL][tT][oO]:[^"]*)"([^>]*>);\1\2="/#safe/\3"\4;g
54 s;(<[^>]+ )(href|src)="([^#/"][^"]*)"([^>]*>);\1\2="'"${refpfx}"'\3"\4;g
55 s;(<[^>]+ )(href|src)="/#safe/([^"]*)"([^>]*>);\1\2="\3"\4;g
57 printf '</article></div>'