changeset 671:11b6e5c7ba86

Use stChkRequestItemFail() where appropriate.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 06 Nov 2014 21:27:18 +0200
parents 8a091dc8d608
children 123aceb0ac4f
files admajax.php
diffstat 1 files changed, 51 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Thu Nov 06 21:26:48 2014 +0200
+++ b/admajax.php	Thu Nov 06 21:27:18 2014 +0200
@@ -14,15 +14,13 @@
 {
   $res = TRUE;
 
-  if (!stChkRequestItem("name", $fake,
-      array(CHK_ISGT, VT_STR, 0, "Compo name too short"),
-      array(CHK_LTEQ, VT_STR, SET_LEN_COMPO_NAME, "Compo name too long.")))
-    $res = FALSE;
+  stChkRequestItemFail("name", $fake, $res,
+    array(CHK_ISGT, VT_STR, 0, "Compo name too short"),
+    array(CHK_LTEQ, VT_STR, SET_LEN_COMPO_NAME, "Compo name too long."));
 
-  if (!stChkRequestItem("description", $fake,
-      array(CHK_ISGT, VT_STR, 10, "Compo description too short"),
-      array(CHK_LTEQ, VT_STR, SET_LEN_COMPO_DESC, "Compo description too long.")))
-    $res = FALSE;
+  stChkRequestItemFail("description", $fake, $res,
+    array(CHK_ISGT, VT_STR, 10, "Compo description too short"),
+    array(CHK_LTEQ, VT_STR, SET_LEN_COMPO_DESC, "Compo description too long."));
 
   // Not a full check?
   if (!$full)
@@ -32,23 +30,19 @@
   switch ($ctype)
   {
     case COMPO_NORMAL:
-      if (!stChkRequestItem("voting", $fake,
-        array(CHK_TYPE, VT_BOOL, "Invalid data.")))
-        $res = FALSE;
+      stChkRequestItemFail("voting", $fake, $res,
+        array(CHK_TYPE, VT_BOOL, "Invalid data."));
       break;
   }
 
-  if (!stChkRequestItem("visible", $fake,
-      array(CHK_TYPE, VT_BOOL, "Invalid data.")))
-    $res = FALSE;
+  stChkRequestItemFail("visible", $fake, $res,
+    array(CHK_TYPE, VT_BOOL, "Invalid data."));
 
-  if (!stChkRequestItem("show_authors", $fake,
-      array(CHK_TYPE, VT_BOOL, "Invalid data.")))
-    $res = FALSE;
+  stChkRequestItemFail("show_authors", $fake, $res,
+    array(CHK_TYPE, VT_BOOL, "Invalid data."));
 
-  if (!stChkRequestItem("cpath", $fake,
-      array(CHK_LTEQ, VT_STR, SET_LEN_COMPO_PATH, "Compo file path too long.")))
-    $res = FALSE;
+  stChkRequestItemFail("cpath", $fake, $res,
+    array(CHK_LTEQ, VT_STR, SET_LEN_COMPO_PATH, "Compo file path too long."));
 
   return $res;
 }
@@ -56,44 +50,48 @@
 
 function stValidateRequestEntryData(&$compo_id)
 {
-  return
-    stChkRequestItem("name", $fake,
-      array(CHK_ISGT, VT_STR, 0, "Entry name too short."),
-      array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_NAME, "Entry name too long.")
-    ) &&
-    stChkRequestItem("author", $fake,
-      array(CHK_ISGT, VT_STR, 0, "Author name not set."),
-      array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_AUTHOR, "Entry author too long.")
-    ) &&
-    stChkRequestItem("filename", $fake,
-      array(CHK_TYPE, VT_TEXT, "Invalid data."),
-      array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_FILENAME, "Entry filename too long.")
-    ) &&
-    stChkRequestItem("info", $fake,
-      array(CHK_TYPE, VT_TEXT, "Invalid data."),
-      array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_INFO, "Entry info too long.")
-    ) &&
-    stChkRequestItem("compo_id", $compo_id,
-      array(CHK_TYPE, VT_INT, "Invalid compo ID.")
-    );
+  $res = TRUE;
+
+  stChkRequestItemFail("name", $fake, $res,
+    array(CHK_ISGT, VT_STR, 0, "Entry name too short."),
+    array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_NAME, "Entry name too long."));
+
+  stChkRequestItemFail("author", $fake, $res,
+    array(CHK_ISGT, VT_STR, 0, "Author name not set."),
+    array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_AUTHOR, "Entry author too long."));
+
+  stChkRequestItemFail("filename", $fake, $res,
+    array(CHK_TYPE, VT_TEXT, "Invalid data."),
+    array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_FILENAME, "Entry filename too long."));
+
+  stChkRequestItemFail("info", $fake, $res,
+    array(CHK_TYPE, VT_TEXT, "Invalid data."),
+    array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_INFO, "Entry info too long."));
+
+  stChkRequestItemFail("compo_id", $compo_id, $res,
+    array(CHK_TYPE, VT_INT, "Invalid compo ID."));
+
+  return $res;
 }
 
 
 function stValidateRequestNewsData()
 {
-  return
-    stChkRequestItem("text", $fake,
-      array(CHK_ISGT, VT_STR, 0, "News text too short."),
-      array(CHK_LTEQ, VT_STR, SET_LEN_NEWS_TEXT, "News text too long.")
-    ) &&
-    stChkRequestItem("author", $fake,
-      array(CHK_ISGT, VT_STR, 0, "News author name too short."),
-      array(CHK_LTEQ, VT_STR, SET_LEN_NEWS_AUTHOR, "News author name too long.")
-    ) &&
-    stChkRequestItem("title", $fake,
-      array(CHK_ISGT, VT_STR, 0, "News title too short."),
-      array(CHK_LTEQ, VT_STR, SET_LEN_NEWS_TITLE, "News title too long.")
-    );
+  $res = TRUE;
+
+  stChkRequestItemFail("text", $fake, $res,
+    array(CHK_ISGT, VT_STR, 0, "News text too short."),
+    array(CHK_LTEQ, VT_STR, SET_LEN_NEWS_TEXT, "News text too long."));
+
+  stChkRequestItemFail("author", $fake, $res,
+    array(CHK_ISGT, VT_STR, 0, "News author name too short."),
+    array(CHK_LTEQ, VT_STR, SET_LEN_NEWS_AUTHOR, "News author name too long."));
+
+  stChkRequestItemFail("title", $fake, $res,
+    array(CHK_ISGT, VT_STR, 0, "News title too short."),
+    array(CHK_LTEQ, VT_STR, SET_LEN_NEWS_TITLE, "News title too long."));
+
+  return $res;
 }