Voice Of the People


RSS
Follow by Email
Facebook
Google+
Twitter

©Copyright 2017 Voice Of the People | Campaign for a Citizen Cabinet. All rights reserved.

"); //##############add code for how to deal when we don't discover something in the JSON queries var ak = Request.hasParameter("action_KEY") ? Request.getParameter("action_KEY") : ""; //get the action_KEY from the URL var survey = Request.hasParameter("survey") ? Request.getParameter("survey") : ""; //get a survey ID from the URL - we're now using this instead of action_KEY to look for the right tag //var tag = Crawler.getXML("http://surveys.publicconsensus.org/wp-json/wp/v2/tags?slug="+ak); //look up the tag_ID for the action_KEY var tag = Crawler.getXML("http://surveys.publicconsensus.org/wp-json/wp/v2/tags?slug="+survey); //look up the tag_ID for the survey ID print("tag: "+tag+"
"); var qlist = []; //create an array to store all of the question_ parameters var tlist = []; //create an array to store questions and translations if (tag.countBytes() > 2) { //make sure we actually get a tag -- needs to be 2 here because this gets returned with [] if empty tag = tag.slice(1,-1); //strip brackets from string that gets returned jtag = JSON.parse(tag); //JSON parse the result var tid = jtag.id; //store the tag id print("tid: "+tid+"
"); for each (parameter in Request.getParameterNames()) { if (parameter.startsWith("question_") == true) { //look for just parameters that start question_ qlist.push(parameter); //add them to the array } } print("qlist: "+qlist+"
"); if (qlist.length > 0) { //make sure we actually have some questions in the array for (q in qlist) { //iterate through all items in the array var question = qlist[q]; //make the first item a variable print("question: "+question+"
"); var response = Request.getParameter(question); //get the response for this question print ("response: "+response+"
"); response = response.replace(/\s/g,"-"); //replace any spaces (regular expression \s) in response with - to correspond with Wordpress category structure; print ("new response: "+response+"
"); var category = Crawler.getXML("http://surveys.publicconsensus.org/wp-json/wp/v2/categories?slug="+response); //find the category id for that response print ("category: "+category+"
"); if (category.countBytes() > 2) {//make sure we actually get a category category = category.slice(1,-1); //strip brackets from string that gets returned jcat = JSON.parse(category); //JSON parse the result var cid = jcat.id //store the category id print("cid: "+cid+"
"); var url = "http://surveys.publicconsensus.org/wp-json/wp/v2/translation?tags="+tid+"&categories="+cid+"&search="+question; //build the URL to use to search for the correct translation for this particular question print("url: "+url+"
"); var translations = Crawler.getXML(url);//get the translation from wordpress API print ("translations: "+translations+"
"); print ("translations length: "+translations.countBytes()+"
"); if (translations.countBytes() > 2) {//make sure we actually get translations, needs to be 2 here because this gets returned with [] if empty translations = translations.slice(1,-1); //strip brackets from string that gets returned //print("translations: "+translations+"
"); jtrans = JSON.parse(translations); //JSON parse the result var trans = jtrans.translation; //put the transation for this question into a variable //print("translation: "+trans+"
"); tlist.push('{"question":"'+question+'","translation":"'+trans+'"}'); //add this question and translation to the array print("tlist: "+tlist+"
"); //print("tlist length: "+tlist.length+"
"); } //end if translations.length > 0 else { print("translations.length > 0 failed
"); } }//end if category.length > 0 else { print("category.length > 0 failed
"); } } //end for q in qlist } //end if qlist.length > 0 else { print("no questions!"); } }//end if tag.length > 0 else { print("tag.length > 0 failed
"); } print(""); //and we're done with SalsaScript (except for a tiny bit below) ?> There was an error parsing this template. TypeError: The content of elements must consist of well-formed character data or markup. (salsa#943)