From: Richard Kettlewell Date: Sun, 11 May 2008 14:50:13 +0000 (+0100) Subject: @image expansion X-Git-Tag: 4.0~76^2~31 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/30d855885418ebe3e7bf76fd800909cdf7bb178a?ds=sidebyside @image expansion --- diff --git a/server/dcgi.c b/server/dcgi.c index 1ba638f..4ad1b5c 100644 --- a/server/dcgi.c +++ b/server/dcgi.c @@ -755,36 +755,6 @@ static void exp_fullname(int attribute((unused)) nargs, cgi_output(output, "%.*s", ds->nav_len, ds->nav_path); } -static void exp_basename(int nargs, - char **args, - cgi_sink *output, - void *u) { - dcgi_state *ds = u; - const char *s; - - if(nargs) { - if((s = strrchr(args[0], '/'))) ++s; - else s = args[0]; - cgi_output(output, "%s", s); - } else - cgi_output(output, "%.*s", ds->nav_len - ds->nav_dirlen - 1, - ds->nav_path + ds->nav_dirlen + 1); -} - -static void exp_dirname(int nargs, - char **args, - cgi_sink *output, - void *u) { - dcgi_state *ds = u; - const char *s; - - if(nargs) { - if((s = strrchr(args[0], '/'))) - cgi_output(output, "%.*s", (int)(s - args[0]), args[0]); - } else - cgi_output(output, "%.*s", ds->nav_dirlen, ds->nav_path); -} - static void exp_files(int attribute((unused)) nargs, char **args, cgi_sink *output, @@ -836,26 +806,6 @@ static void exp_nfiles(int attribute((unused)) nargs, cgi_output(output, "1"); } -static void exp_image(int attribute((unused)) nargs, - char **args, - cgi_sink *output, - void attribute((unused)) *u) { - char *labelname; - const char *imagestem; - - byte_xasprintf(&labelname, "images.%s", args[0]); - if(cgi_label_exists(labelname)) - imagestem = cgi_label(labelname); - else if(strchr(args[0], '.')) - imagestem = args[0]; - else - byte_xasprintf((char **)&imagestem, "%s.png", args[0]); - if(cgi_label_exists("url.static")) - cgi_output(output, "%s/%s", cgi_label("url.static"), imagestem); - else - cgi_output(output, "/disorder/%s", imagestem); -} - /* Local Variables: c-basic-offset:2 diff --git a/server/lookup.c b/server/lookup.c index 452cd53..75680e7 100644 --- a/server/lookup.c +++ b/server/lookup.c @@ -119,19 +119,19 @@ void dcgi_lookup(unsigned want) { /** @brief Locate a track by ID */ struct queue_entry *dcgi_findtrack(const char *id) { - struct queue_entry *q, **qq; + struct queue_entry **qq; - if(queuemap && (qq = hash_find(id))) - return *q; + if(queuemap && (qq = hash_find(queuemap, id))) + return *qq; dcgi_lookup(DCGI_PLAYING); - if(queuemap && (qq = hash_find(id))) - return *q; + if(queuemap && (qq = hash_find(queuemap, id))) + return *qq; dcgi_lookup(DCGI_QUEUE); - if(queuemap && (qq = hash_find(id))) - return *q; + if(queuemap && (qq = hash_find(queuemap, id))) + return *qq; dcgi_lookup(DCGI_RECENT); - if(queuemap && (qq = hash_find(id))) - return *q; + if(queuemap && (qq = hash_find(queuemap, id))) + return *qq; return NULL; } diff --git a/server/macros-disorder.c b/server/macros-disorder.c index 8b5b486..b35ad24 100644 --- a/server/macros-disorder.c +++ b/server/macros-disorder.c @@ -737,11 +737,52 @@ static int exp_error(int attribute((unused)) nargs, return sink_writes(output, cgi_sgmlquote(dcgi_error_string)) < 0 ? -1 : 0; } +/* @image{NAME} + * + * Expands to the URL of the image called NAME. + * + * Firstly if there is a label called images.NAME then the image stem will be + * the value of that label. Otherwise the stem will be NAME.png. + * + * If the label url.static exists then it will give the base URL for images. + * Otherwise the base url will be /disorder/. + */ +static int exp_image(int attribute((unused)) nargs, + char **args, + struct sink *output, + void attribute((unused)) *u) { + const char *url, *stem; + char *labelname; + + /* Compute the stem */ + byte_xasprintf(&labelname, "images.%s", args[0]); + if(option_label_exists(labelname)) + stem = option_label(labelname); + else + byte_xasprintf((char **)&stem, "%s.png", args[0]); + /* If the stem looks like it's reasonalby complete, use that */ + if(stem[0] == '/' + || !strncmp(stem, "http:", 5) + || !strncmp(stem, "https:", 6)) + url = stem; + else { + /* Compute the URL */ + if(option_label_exists("url.static")) + byte_xasprintf((char **)&url, "%s/%s", + option_label("url.static"), stem); + else + /* Default base is /disorder */ + byte_xasprintf((char **)&url, "/disorder/%s", stem); + } + return sink_writes(output, cgi_sgmlquote(url)) < 0 ? -1 : 0; +} + /** @brief Register DisOrder-specific expansions */ void dcgi_expansions(void) { mx_register("arg", 1, 1, exp_arg); mx_register("enabled", 0, 0, exp_enabled); mx_register("error", 0, 0, exp_error); + mx_register("image", 1, 1, exp_image); mx_register("isnew", 0, 0, exp_isnew); mx_register("isplaying", 0, 0, exp_isplaying); mx_register("isplaying", 0, 0, exp_isqueue); diff --git a/templates/macros.tmpl b/templates/macros.tmpl index af62b4c..432cbe3 100644 --- a/templates/macros.tmpl +++ b/templates/macros.tmpl @@ -84,10 +84,12 @@ USA { @label{@what.scratch} } {@label{@what.scratch}}} @@ -101,10 +103,12 @@ USA { @label{playing.@dir} } {@label{playing.@dir}}} + width=@width height=@height + title="@label{playing.@q{@dir}verbose}" + alt="@label{playing.@dir}">}} }@# diff --git a/templates/playing.tmpl b/templates/playing.tmpl index ba8af01..bd1f635 100644 --- a/templates/playing.tmpl +++ b/templates/playing.tmpl @@ -41,10 +41,12 @@ USA { @label{volume.@dir} } - {}} + {}} @include{macros.tmpl} }@#