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,
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
/** @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;
}
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);
{<a class=imgbutton
href="@url?action=remove&id=@id@back">
<img class=button src="@image{remove}"
+ width=@width height=@height
title="@label{@what.removeverbose}"
alt="@label{@what.scratch}">
</a>}
{<img class=button src="@image{noremove}"
+ width=@width height=@height
title="@label{@what.removeverbose}"
alt="@label{@what.scratch}">}}
{<a class=imgbutton
href="@url?action=move&id=@id&delta=@delta@back">
<img class=button src="@image{@dir}"
+ width=@width height=@height
title="@label{playing.@q{@dir}verbose}"
alt="@label{playing.@dir}">
</a>}
{<img class=button src="@image{no@dir}"
- title="@label{playing.@q{@dir}verbose}"
- alt="@label{playing.@dir}">}}
+ width=@width height=@height
+ title="@label{playing.@q{@dir}verbose}"
+ alt="@label{playing.@dir}">}}
}@#
{<a class=imgbutton
href="@url?action=volume&delta=@sign@label{volume.resolution}@back">
<img class=button src="@image{@dir}"
+ width=@width height=@height
alt="@label{volume.@dir}"
title="@label{volume.@q{@dir}verbose}">
</a>}
- {<img class=button src="@image{no@dir}">}}
+ {<img class=button width=@width height=@height
+ src="@image{no@dir}">}}
@include{macros.tmpl}
}@#