function findSetting(&$settings, $target, $removeFound = true) { foreach ($settings as $key => $setting) { $test = removeLabel($setting, $target); if ($test !== false) { if ($removeFound) { unset($settings[$key]); } return $test; } } return false; }
} if (false !== stripos($string, 'youtu.be')) { return true; } return false; } if (!isValidYouTube($cue)) { throw new InvalidArgumentException('The given video source is not ' . 'supported. The cue should be a YouTube URL.'); } // extract submitOnDone and preventEarlySubmit settings from $settings $submitOnDone = true; $preventEarlySubmit = true; $settings = explode('|', $settings); foreach ($settings as $setting) { $settingSubmit = removeLabel($setting, 'submitOnDone'); $settingPrevent = removeLabel($setting, 'preventEarlySubmit'); if ($settingSubmit === 'false') { $submitOnDone = false; } if ($settingPrevent === 'false') { $preventEarlySubmit = false; } } // get video ID $videoId = youtubeUrlCleaner($cue, true); // get start and end time from stim file columns if (!isset($startTime) or !is_numeric($startTime)) { $startTime = 0; } if (!isset($endTime) or !is_numeric($endTime)) { $endTime = 'na';
public function __invoke() { $this->createLabel(); $alert_text = []; $history = []; $currentTime = new \DateTime(); $today = $currentTime->format('m') + 1 + "/" + $currentTime . getDate() + "/" + $currentTime->format('Y'); $keywordIterator; $line_counter = 0; while ($keywordIterator->hasNext()) { $keyword = keywordIterator . next(); $line_counter++; $current_quality_score = $keyword->qualityScore; $keywordLabelsIterator = keyword . labels() . withCondition("Name STARTS_WITH 'QS: '") . get(); if ($keywordLabelsIterator->hasNext()) { $keyword_label = $keywordLabelsIterator . next(); $matches = new RegExp('QS: ([0-9]+)$') . exec($keyword_label . getName()); $old_quality_score = $matches[1]; } else { $old_quality_score = 0; } // For the history also note the change or whether this keyword is new if ($old_quality_score > 0) { $change = $current_quality_score - $old_quality_score; } else { $change = "NEW"; } $row = [$today, $keyword . getCampaign() . getName(), $keyword . getAdGroup() . getName(), $keyword . getText(), $current_quality_score, $change]; $history . push(row); // If there is a previously tracked quality score and it's different from the current one... if ($old_quality_score > 0 && $current_quality_score != $old_quality_score) { // Make a note of this to log it and possibly send it via email later $alert_text . push($current_quality_score + "\t" + $old_quality_score + "\t" + $change + "\t" + $keyword . getText()); // Remove the old label $keyword . removeLabel($keyword_label . getName()); } // Store the current QS for the next time by using a label $keyword . applyLabel("QS: " + $current_quality_score); } if ($line_counter == 0) { $this->logger->log("Couldn't find any keywords marked for quality score tracking. To mark keywords for tracking, apply the label '" + $label_name + "' to those keywords."); return; } $this->logger->log("Tracked " + $line_counter + " keyword quality scores. To select different keywords for tracking, apply the label '" + $label_name + "' to those keywords."); // Store history $history_sheet = spreadsheet . getSheetByName('QS history'); $history_sheet . getRange($history_sheet . getLastRow() + 1, 1, $history . length, 6) . setValues($history); // If there are notes for alerts then prepare a message to log and possibly send via email if ($alert_text . length) { $message = "The following quality score changes were discovered:\nNew\tOld\tChange\tKeyword\n"; for ($i = 0; $i < count($alert_text); $i++) { $message += $alert_text[i] + "\n"; } // Also include a link to the spreadsheet $message += "\n" + "The complete history is available at " + $spreadsheet . getUrl(); $this->logger->log($message); // If there is an email address send out a notification if ($email_address && $email_address != "YOUR_EMAIL_HERE") { $this->mailer->sendEmail($email_address, "Quality Score Tracker: Changes detected", $message); } } }
$value[] = 1; } } $answerCount = count($answers); $input = 'one'; $expandOutput = true; $settings = explode('|', $settings); foreach ($settings as $setting) { if ($test = removeLabel($setting, 'input')) { $test = strtolower($test); if ($test === 'one' or $test === 'many' or is_numeric($test)) { $input = $test; } else { exit('Error: invalid "input" setting for trial type "' . $trialType . '", on trial ' . $currentPos); } } elseif ($test = removeLabel($setting, 'expandOutput')) { $test = strtolower($test); if ($test === 'no' or $test === 'false') { $expandOutput = false; } } } $respExp = array(); if ($input === 'one') { $responseFormatted = strtolower(preg_replace("/[^a-zA-Z0-9'\\- ]+/", " ", $_POST['Response'])); //replace most symbols with spaces, so that if they entered like word,word,word, we get separate words $responseFormatted = trim(preg_replace("/\\s+/", " ", $responseFormatted)); //then, set all spaces and newlines to a single space. this assumes that the answers dont have non-alphanumerical characters in them $respExp = explode(' ', $responseFormatted); } else { $i = 1;
<div class="prompt"><?php echo trim($prompts[0]); ?> </div> <?php if (isset($prompts[1])) { $cues = explode('|', $cue); $answers = explode('|', $answer); foreach ($cues as $i => $thisCue) { echo str_replace(array('$cue', '$answer'), array($thisCue, $answers[$i]), $prompts[1]); } } $input = 'one'; $settings = explode('|', $settings); foreach ($settings as $setting) { if ($test = removeLabel($setting, 'input')) { $test = strtolower($test); if ($test === 'one' or $test === 'many' or is_numeric($test)) { $input = $test; } else { exit('Error: invalid "input" setting for trial type "' . $trialType . '", on trial ' . $currentPos); } } } if ($input === 'one') { ?> <div class="pad"> <textarea rows="20" cols="55" name="Response" class="collectorInput" wrap="physical" value=""></textarea> <br><button class="collectorButton collectorAdvance" id="FormSubmitButton" autofocus>Submit</button> </div> <?php
$horizontal = false; } elseif (removeLabel($setting, 'shuffle') !== false) { $unlabeled = removeLabel($setting, 'shuffle'); if (removeLabel($unlabeled, 'button') !== false) { $setting = $unlabeled; $theseAreButtons = true; } else { shuffle($buttons); } } elseif (removeLabel($setting, 'share') !== false) { $share = removeLabel($setting, 'share'); } else { $theseAreButtons = true; } if ($theseAreButtons) { $theseButtons = removeLabel($setting, 'button'); $theseButtons = trimExplode(';', $theseButtons); $newButtons = array(); foreach ($theseButtons as $thisButton) { if ($thisButton === '') { continue; } if ($thisButton[0] === '$') { $sep = strrpos($thisButton, '['); if ($sep === false) { $col = substr($thisButton, 1); $index = $item; } else { $col = substr($thisButton, 1, $sep - 1); $index = substr($thisButton, $sep + 1, strrpos($thisButton, ']') - $sep - 1); }