chiark / gitweb /
@image expansion
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 11 May 2008 14:50:13 +0000 (15:50 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 11 May 2008 14:50:13 +0000 (15:50 +0100)
server/dcgi.c
server/lookup.c
server/macros-disorder.c
templates/macros.tmpl
templates/playing.tmpl

index 1ba638f..4ad1b5c 100644 (file)
@@ -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
index 452cd53..75680e7 100644 (file)
@@ -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;
 }
 
index 8b5b486..b35ad24 100644 (file)
@@ -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);
index af62b4c..432cbe3 100644 (file)
@@ -84,10 +84,12 @@ USA
             {<a class=imgbutton
                 href="@url?action=remove&#38;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}">}}
 
@@ -101,10 +103,12 @@ USA
             {<a class=imgbutton
                 href="@url?action=move&#38;id=@id&#38;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}">}}
 }@#
index ba8af01..bd1f635 100644 (file)
@@ -41,10 +41,12 @@ USA
                  {<a class=imgbutton
                     href="@url?action=volume&#38;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}
 }@#