Example #1
0
 public function Resize($image, $newWidth, $targetName)
 {
     if (!file_exists(PUBLIC_ROOT . $image)) {
         $image = '/assets/images/not-found.gif';
     }
     $imgInfo = getimagesize(PUBLIC_ROOT . $image);
     $oldWidth = $imgInfo[0];
     $oldHeight = $imgInfo[1];
     $changeRatio = $oldWidth / $newWidth;
     $newHeight = round($oldHeight / $changeRatio);
     $newImage = imagecreatetruecolor($newWidth, $newHeight);
     $source = $this->load(PUBLIC_ROOT . $image);
     if ($this->imageType == IMAGETYPE_PNG) {
         imagealphablending($newImage, false);
         imagesavealpha($newImage, true);
         $transparent = imagecolorallocatealpha($newImage, 255, 255, 255, 127);
         imagefilledrectangle($newImage, 0, 0, $newWidth, $newHeight, $transparent);
     }
     imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $oldWidth, $oldHeight);
     header('Content-Type: image/jpeg');
     imagejpeg($newImage, $targetName, 100);
     Debugger::debug($targetName, 'TARGET');
     //$this->save($targetName);
     $this->image = $newImage;
     imagedestroy($newImage);
 }
Example #2
0
 public function processAPI()
 {
     Debugger::debug('API_' . ucwords($this->endpoint));
     if (class_exists('API_' . ucwords($this->endpoint))) {
         return $this->_response($this->getResult());
     }
     return $this->_response(array('error' => "Invalid Endpoint: {$this->endpoint}"), 404);
 }
Example #3
0
 private static function connect()
 {
     try {
         self::$db = new \PDO('mysql:host=' . self::$dbHost . ';dbname=' . self::$dbName . ';charset=utf8', self::$dbUser, self::$dbPass);
         self::$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
         Debugger::debug('error');
         Errors::handle($e, 'sqlerr');
     }
 }
Example #4
0
 public function curlCall($endpoint, $curlPostData = null)
 {
     $curl = curl_init(REST_URL . $endpoint);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     Debugger::debug($endpoint, '$endpoint');
     Debugger::debug($curlPostData, '$curlPostData');
     if (!empty($curlPostData)) {
         Debugger::debug('adding post');
         curl_setopt($curl, CURLOPT_POST, true);
         curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPostData);
     }
     $curlResponse = curl_exec($curl);
     curl_close($curl);
     Debugger::debug($curlResponse, 'CURL response');
     return $curlResponse;
 }
Example #5
0
 public function create($params = null)
 {
     $result = new API_Response();
     if (!empty($_POST)) {
         $user = new User();
         $userId = $user->create($_POST['username'], $_POST['email'], $_POST['password'], $_POST['gender'], $_POST['postcode']);
         //$valid = false;
         //echo gettype($userId);
         \Debugger::debug($userId, 'user id');
         if ($userId) {
             $result->addItem('message', 'User id ' . $userId . ' inserted');
             $result->addItem('userId', $userId);
             $result->addItem('success', true);
         } else {
             $result->addItem('message', 'User id inserted');
             $result->addItem('success', false);
         }
     } else {
         $result->addItem('message', 'POST missing');
         $result->addItem('success', false);
     }
     return $result->getResult();
 }
Example #6
0
 /**
  * Parse a BBCode string and convert it into HTML.
  *
  * Core parser.  This is where all the magic begins and ends.
  * Core parsing routine.  Call with a BBCode string, and it returns an HTML string.
  *
  * @param string $string The BBCode string to parse.
  * @return string Returns the HTML version of {@link $string}.
  */
 public function parse($string)
 {
     Debugger::debug("<b>Parse Begin:</b> input string is " . strlen($string) . " characters long:<br>\n" . "<b>Parse:</b> input: <tt>" . htmlspecialchars(addcslashes($string, "..\\\"'")) . "</tt><br>\n");
     // The lexer is responsible for converting individual characters to tokens,
     // and uses preg_split to do most of its magic.  Because it uses preg_split
     // and not a character-by-character tokenizer, the structure of the input
     // must be known in advance, which is why the tag marker cannot be changed
     // during the parse.
     $this->lexer = new BBCodeLexer($string, $this->tag_marker);
     $this->lexer->debug = $this->debug;
     // If we're fuzzily limiting the text length, see if we need to actually
     // cut it off, or if it's close enough to not be worth the effort.
     $old_output_limit = $this->output_limit;
     Debugger::debug("weee");
     if ($this->output_limit > 0) {
         if ($this->debug) {
             Debugger::debug("<b>Parse:</b> Limiting text length to {$this->output_limit}.<br>\n");
         }
         if (strlen($string) < $this->output_limit) {
             // Easy case:  A short string can't possibly be longer than the output
             // limit, so just turn off the output limit.
             $this->output_limit = 0;
             if ($this->debug) {
                 Debugger::debug("<b>Parse:</b> Not bothering to limit:  Text is too short already.<br>\n");
             }
         } else {
             if ($this->limit_precision > 0) {
                 // We're using fuzzy precision, so make a guess as to how long the text is,
                 // and then decide whether we can let this string slide through based on the
                 // limit precision.
                 $guess_length = $this->lexer->guessTextLength();
                 if ($this->debug) {
                     Debugger::debug("<b>Parse:</b> Maybe not:  Fuzzy limiting enabled, and approximate text length is {$guess_length}.<br>\n");
                 }
                 if ($guess_length < $this->output_limit * ($this->limit_precision + 1.0)) {
                     if ($this->debug) {
                         Debugger::debug("<b>Parse:</b> Not limiting text; it's close enough to the limit to be acceptable.<br>\n");
                     }
                     $this->output_limit = 0;
                 } else {
                     if ($this->debug) {
                         Debugger::debug("<b>Parse:</b> Limiting text; it's definitely too long.<br>\n");
                     }
                 }
             }
         }
     }
     // The token stack is used to perform a document-tree walk without actually
     // building the document tree, and is an essential component of our input-
     // validation algorithm.
     $this->stack = [];
     // There are no start tags (yet).
     $this->start_tags = [];
     // There are no unmatched start tags (yet).
     $this->lost_start_tags = [];
     // There is no text yet.
     $this->text_length = 0;
     $this->was_limited = false;
     // Remove any initial whitespace in pre-trim mode.
     if (strlen($this->pre_trim) > 0) {
         $this->cleanupWSByEatingInput($this->pre_trim);
     }
     // In plain mode, we generate newlines instead of <br> tags.
     $newline = $this->plain_mode ? "\n" : "<br>\n";
     Debugger::debug("hi");
     // This is a fairly straightforward push-down automaton operating in LL(1) mode.  For
     // clarity's sake, we break the tag-processing code into separate functions, but we
     // keep the text/whitespace/newline code here for performance reasons.
     while (true) {
         if (($token_type = $this->lexer->nextToken()) == self::BBCODE_EOI) {
             break;
         }
         if ($this->debug) {
             Debugger::debug("<b>Parse:</b> Stack contents: <tt>" . $this->dumpStack() . "</tt><br>\n");
         }
         switch ($token_type) {
             case self::BBCODE_TEXT:
                 // Text is like an arithmetic operand, so just push it onto the stack because we
                 // won't know what to do with it until we reach an operator (e.g., a tag or EOI).
                 if ($this->debug) {
                     Debugger::debug("<hr />\n<b>Internal_ParseTextToken:</b> fixup and push text: <tt>" . htmlspecialchars($this->lexer->text) . "</tt><br>\n");
                 }
                 // If this token pushes us past the output limit, split it up on a whitespace
                 // boundary, add as much as we can, and then abort.
                 if ($this->output_limit > 0 && $this->text_length + strlen($this->lexer->text) >= $this->output_limit) {
                     $text = $this->limitText($this->lexer->text, $this->output_limit - $this->text_length);
                     if (strlen($text) > 0) {
                         $this->text_length += strlen($text);
                         $this->stack[] = array(self::BBCODE_STACK_TOKEN => self::BBCODE_TEXT, self::BBCODE_STACK_TEXT => $this->fixupOutput($text), self::BBCODE_STACK_TAG => false, self::BBCODE_STACK_CLASS => $this->current_class);
                     }
                     $this->doLimit();
                     break 2;
                 }
                 $this->text_length += strlen($this->lexer->text);
                 // Push this text token onto the stack.
                 $this->stack[] = array(self::BBCODE_STACK_TOKEN => self::BBCODE_TEXT, self::BBCODE_STACK_TEXT => $this->fixupOutput($this->lexer->text), self::BBCODE_STACK_TAG => false, self::BBCODE_STACK_CLASS => $this->current_class);
                 break;
             case self::BBCODE_WS:
                 // Whitespace is like an operand too, so just push it onto the stack, but
                 // sanitize it by removing all non-tab non-space characters.
                 if ($this->debug) {
                     Debugger::debug("<hr />\n<b>Internal_ParseWhitespaceToken:</b> fixup and push whitespace<br>\n");
                 }
                 // If this token pushes us past the output limit, don't process anything further.
                 if ($this->output_limit > 0 && $this->text_length + strlen($this->lexer->text) >= $this->output_limit) {
                     $this->doLimit();
                     break 2;
                 }
                 $this->text_length += strlen($this->lexer->text);
                 // Push this whitespace onto the stack.
                 $this->stack[] = array(self::BBCODE_STACK_TOKEN => self::BBCODE_WS, self::BBCODE_STACK_TEXT => $this->lexer->text, self::BBCODE_STACK_TAG => false, self::BBCODE_STACK_CLASS => $this->current_class);
                 break;
             case self::BBCODE_NL:
                 // Newlines are really like tags in disguise:  They insert a replaced
                 // element into the output, and are actually more-or-less like plain text.
                 if ($this->debug) {
                     Debugger::debug("<hr />\n<b>Internal_ParseNewlineToken:</b> got a newline.<br>\n");
                 }
                 if ($this->ignore_newlines) {
                     if ($this->debug) {
                         Debugger::debug("<b>Internal_ParseNewlineToken:</b> push newline as whitespace.<br>\n");
                     }
                     // If this token pushes us past the output limit, don't process anything further.
                     if ($this->output_limit > 0 && $this->text_length + 1 >= $this->output_limit) {
                         $this->doLimit();
                         break 2;
                     }
                     $this->text_length += 1;
                     // In $ignore_newlines mode, we simply push the newline as whitespace.
                     // Note that this can yield output that's slightly different than the
                     // input:  For example, a "\r\n" input will produce a "\n" output; but
                     // this should still be acceptable, since we're working with text, not
                     // binary data.
                     $this->stack[] = array(self::BBCODE_STACK_TOKEN => self::BBCODE_WS, self::BBCODE_STACK_TEXT => "\n", self::BBCODE_STACK_TAG => false, self::BBCODE_STACK_CLASS => $this->current_class);
                 } else {
                     // Any whitespace before a newline isn't worth outputting, so if there's
                     // whitespace sitting on top of the stack, remove it so that it doesn't
                     // get outputted.
                     $this->cleanupWSByPoppingStack("s", $this->stack);
                     if ($this->debug) {
                         Debugger::debug("<b>Internal_ParseNewlineToken:</b> push newline.<br>\n");
                     }
                     // If this token pushes us past the output limit, don't process anything further.
                     if ($this->output_limit > 0 && $this->text_length + 1 >= $this->output_limit) {
                         $this->doLimit();
                         break 2;
                     }
                     $this->text_length += 1;
                     // Add the newline to the stack.
                     $this->stack[] = array(self::BBCODE_STACK_TOKEN => self::BBCODE_NL, self::BBCODE_STACK_TEXT => $newline, self::BBCODE_STACK_TAG => false, self::BBCODE_STACK_CLASS => $this->current_class);
                     // Any whitespace after a newline is meaningless, so if there's whitespace
                     // lingering on the input after this, remove it now.
                     $this->cleanupWSByEatingInput("s");
                 }
                 break;
             case self::BBCODE_TAG:
                 // Use a separate function to handle tags, because they're complicated.
                 $this->parseStartTagToken();
                 break;
             case self::BBCODE_ENDTAG:
                 // Use a separate function to handle end tags, because they're complicated.
                 $this->parseEndTagToken();
                 break;
             default:
                 break;
         }
     }
     if ($this->debug) {
         Debugger::debug("<hr />\n<b>Parse Done:</b> done main parse; packing stack as text string.<br>\n");
     }
     // Remove any trailing whitespace in post-trim mode.
     if (strlen($this->post_trim) > 0) {
         $this->cleanupWSByPoppingStack($this->post_trim, $this->stack);
     }
     // Everything left on the stack should be HTML (or broken tags), so pop it
     // all off as plain text, concatenate it, and return it.
     $result = $this->generateOutput(0);
     $result = $this->collectTextReverse($result, count($result) - 1);
     // If we changed the limit (in fuzzy-limit mode), set it back.
     $this->output_limit = $old_output_limit;
     // In plain mode, we do just a *little* more cleanup on the whitespace to shorten
     // the output as much as possible.
     if ($this->plain_mode) {
         // Turn all non-newline whitespace characters into single spaces.
         $result = preg_replace("/[\\x00-\\x09\\x0B-\\x20]+/", " ", $result);
         // Turn multiple newlines into at most two newlines.
         $result = preg_replace("/(?:[\\x20]*\\n){2,}[\\x20]*/", "\n\n", $result);
         // Strip off all surrounding whitespace.
         $result = trim($result);
     }
     if ($this->debug) {
         Debugger::debug("<b>Parse:</b> return: <tt>" . htmlspecialchars(addcslashes($result, "..\\\"'")) . "</tt><br>\n");
     }
     return $result;
 }
Example #7
0
 public function load404()
 {
     global $module, $page;
     $module = '404';
     $page = '404';
     $e = new Exception('directing to 404');
     Debugger::debug('dump', 'REDIRECT', null, true);
     return '404';
     //Redirect::handle('/' . ((Site::isAdmin()) ? 'admin/' : '') . '404');
 }
Example #8
0
 /**
  * Format a [url] tag by producing an <a>...</a> element.
  *
  * The URL only allows http, https, mailto, and ftp protocols for safety.
  *
  * @param BBCode $bbcode The {@link BBCode} object doing the parsing.
  * @param int $action The current action being performed on the tag.
  * @param string $name The name of the tag.
  * @param string $default The default value passed to the tag in the form: `[tag=default]`.
  * @param array $params All of the parameters passed to the tag.
  * @param string $content The content of the tag. Only available when {@link $action} is **BBCODE_OUTPUT**.
  * @return string Returns the full HTML url.
  */
 public function doURL(BBCode $bbcode, $action, $name, $default, $params, $content)
 {
     // We can't check this with BBCODE_CHECK because we may have no URL
     // before the content has been processed.
     if ($action == BBCode::BBCODE_CHECK) {
         return true;
     }
     $url = is_string($default) ? $default : $bbcode->unHTMLEncode(strip_tags($content));
     if ($bbcode->isValidURL($url)) {
         if ($bbcode->debug) {
             Debugger::debug('ISVALIDURL');
         }
         if ($bbcode->getURLTargetable() !== false && isset($params['target'])) {
             $target = ' target="' . htmlspecialchars($params['target']) . '"';
         } else {
             $target = '';
         }
         if ($bbcode->getURLTarget() !== false && empty($target)) {
             $target = ' target="' . htmlspecialchars($bbcode->getURLTarget()) . '"';
         }
         // If $detect_urls is on, it's possble the $content is already
         // enclosed in an <a href> tag. Remove that if that is the case.
         $content = preg_replace('/^\\<a [^\\>]*\\>(.*?)<\\/a>$/', "\\1", $content);
         return $bbcode->fillTemplate($bbcode->getURLTemplate(), array("url" => $url, "target" => $target, "content" => $content));
     } else {
         return htmlspecialchars($params['_tag']) . $content . htmlspecialchars($params['_endtag']);
     }
 }
Example #9
0
require_once "classes/Debugger.php";
require_once "classes/SignupGadget.php";
require_once "classes/CommonTools.php";
/* Implementations of the most critical classes */
$configurations = new Configurations();
$page = new Page(1);
$debugger = new Debugger();
$database = new Database();
/* The code */
$signupGadgets = new SignupGadgets();
// Check if the search was performed
$searchString = CommonTools::GET('search');
$year = CommonTools::GET('year');
// Is the search performed?
if ($searchString != null && $searchString != "") {
    $debugger->debug("Searching signup gadgets using search string {$searchString}", "index.php");
    $signupGadgets->selectSearchSignupGadget($searchString);
} else {
    if ($year != null && $year != "") {
        $signupGadgets->selectSignupGadgetsByYear($year);
    } else {
        $signupGadgets->selectOpenGadgetsOrClosedDuringLastDays(7);
    }
}
// Get all selected gadgets to array
$signupGadgets_array = $signupGadgets->getSignupGadgets();
// Print table headers
$page->addContent("<table id=\"signup-gadgets\">");
$page->addContent("<tr id=\"signup-header-row\">");
$page->addContent("<th id=\"signup-name-header\">Ilmo</th><th>Avautuu</th><th>Sulkeutuu</th><th>Tila</th><th>Muokkaa</th><th>Poista</th><th>Muuta tilaa</th>");
$page->addContent("</tr>");
Example #10
0
} else {
    if ($action == "continueandcancelold") {
        $user = new User($signupid);
        $user->cancelUnconfirmedSignupAndRefreshSession();
        header("Location: " . $configurations->webRoot . "confirm/" . $user->getNewSignupId());
    } else {
        // Check that signup is open
        $newSignupGadget = new SignupGadget($signupid);
        $user = null;
        if ($newSignupGadget->isOpen()) {
            $user = new User($signupid);
        } else {
            $debugger->error("Ilmoittautuminen ei ole avoinna.", "queue.php");
        }
        if ($user->getUnconfirmedSignupExists()) {
            $debugger->debug("Unconfirmed signup exists", "queue.php");
            if ($user->getUnconfirmedSignupIsNotTheSameAsThis()) {
                $debugger->debug("Unconfirmed signup exists, but it is not this one", "queue.php");
                $signupgadget = new SignupGadget($user->getOldSignupId());
                $page->addContent("<p><b>Huom!</b> Olet ilmoittautunut jo ilmomasiinassa <b>" . $signupgadget->getTitle() . "</b>, muttet ole vahvistanut ilmoittautumista. " . "Ennen kuin voit ilmoittautua toiseen ilmomasiinaan sinun pitää vahvistaa tai peruuttaa" . " aikasemmat vahvistamattomat ilmoittautumiset.</p>");
                $page->addContent("<p>Valitse mitä haluat tehdä:</p>");
                $page->addContent("<p> >> <a href=\"" . $configurations->webRoot . "continueandcancelold/" . $user->getNewSignupId() . "\">Peruuta aiempi vahvistamaton ilmoittautuminen ja " . "siirry eteenpäin</a></p>");
                $page->addContent("<p> >> <a href=\"" . $configurations->webRoot . "confirmold/" . $user->getOldSignupId() . "\">Siirry vahvistamaan aiempi ilmoittautuminen</a></p>");
                $page->printPage();
            } else {
                header("Location: " . $configurations->webRoot . "confirm/" . $user->getNewSignupId());
            }
        } else {
            header("Location: " . $configurations->webRoot . "confirm/" . $user->getNewSignupId());
        }
    }
Example #11
0
 /**
  * Given a string containing a complete [tag] (including its brackets), break it down into its components and return them as an array.
  *
  * @param string $tag The tag to decode.
  * @return array Returns the array representation of the tag.
  */
 protected function decodeTag($tag)
 {
     Debugger::debug("<b>Lexer::InternalDecodeTag:</b> input: " . htmlspecialchars($tag) . "<br />\n");
     // Create the initial result object.
     $result = ['_tag' => $tag, '_endtag' => '', '_name' => '', '_hasend' => false, '_end' => false, '_default' => false];
     // Strip off the [brackets] around the tag, leaving just its content.
     $tag = substr($tag, 1, strlen($tag) - 2);
     // The starting bracket *must* be followed by a non-whitespace character.
     $ch = ord(substr($tag, 0, 1));
     if ($ch >= 0 && $ch <= 32) {
         return $result;
     }
     // Break it apart into words, quoted text, whitespace, and equal signs.
     $pieces = preg_split("/(\\\"[^\\\"]+\\\"|\\'[^\\']+\\'|=|[\\x00-\\x20]+)/", $tag, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
     $ptr = 0;
     // Handle malformed (empty) tags correctly.
     if (count($pieces) < 1) {
         return $result;
     }
     // The first piece should be the tag name, whatever it is.  If it starts with a /
     // we remove the / and mark it as an end tag.
     if (!empty($pieces[$ptr]) && substr($pieces[$ptr], 0, 1) === '/') {
         $result['_name'] = strtolower(substr($pieces[$ptr++], 1));
         $result['_end'] = true;
     } else {
         $result['_name'] = strtolower($pieces[$ptr++]);
         $result['_end'] = false;
     }
     // Skip whitespace after the tag name.
     while (($type = $this->classifyPiece($ptr, $pieces)) == ' ') {
         $ptr++;
     }
     $params = [];
     // If the next piece is an equal sign, then the tag's default value follows.
     if ($type != '=') {
         $result['_default'] = false;
         $params[] = ['key' => '', 'value' => ''];
     } else {
         $ptr++;
         // Skip whitespace after the initial equal-sign.
         while (($type = $this->classifyPiece($ptr, $pieces)) == ' ') {
             $ptr++;
         }
         // Examine the next (real) piece, and see if it's quoted; if not, we need to
         // use heuristics to guess where the default value begins and ends.
         if ($type == "\"") {
             $value = $this->stripQuotes($pieces[$ptr++]);
         } else {
             // Collect pieces going forward until we reach an = sign or the end of the
             // tag; then rewind before whatever comes before the = sign, and everything
             // between here and there becomes the default value.  This allows tags like
             // [font=Times New Roman size=4] to make sense even though the font name is
             // not quoted.  Note, however, that there's a special initial case, where
             // any equal-signs before whitespace are considered to be part of the parameter
             // as well; this allows an ugly tag like [url=http://foo?bar=baz target=my_window]
             // to behave in a way that makes (tolerable) sense.
             $after_space = false;
             $start = $ptr;
             while (($type = $this->classifyPiece($ptr, $pieces)) != -1) {
                 if ($type == ' ') {
                     $after_space = true;
                 }
                 if ($type == '=' && $after_space) {
                     break;
                 }
                 $ptr++;
             }
             if ($type == -1) {
                 $ptr--;
             }
             // We've now found the first (appropriate) equal-sign after the start of the
             // default value.  (In the example above, that's the "=" after "target".)  We
             // now have to rewind back to the last whitespace to find where the default
             // value ended.
             if ($type == '=') {
                 // Rewind before = sign.
                 $ptr--;
                 // Rewind before any whitespace before = sign.
                 while ($ptr > $start && $this->classifyPiece($ptr, $pieces) == ' ') {
                     $ptr--;
                 }
                 // Rewind before any text elements before that.
                 while ($ptr > $start && $this->classifyPiece($ptr, $pieces) != ' ') {
                     $ptr--;
                 }
             }
             // The default value is everything from $start to $ptr, inclusive.
             $value = "";
             for (; $start <= $ptr; $start++) {
                 if ($this->classifyPiece($start, $pieces) == ' ') {
                     $value .= " ";
                 } else {
                     $value .= $this->stripQuotes($pieces[$start]);
                 }
             }
             $value = trim($value);
             $ptr++;
         }
         $result['_default'] = $value;
         $params[] = ['key' => '', 'value' => $value];
     }
     // The rest of the tag is composed of either floating keys or key=value pairs, so walk through
     // the tag and collect them all.  Again, we have the nasty special case where an equal sign
     // in a parameter but before whitespace counts as part of that parameter.
     while (($type = $this->classifyPiece($ptr, $pieces)) != -1) {
         // Skip whitespace before the next key name.
         while ($type === ' ') {
             $ptr++;
             $type = $this->classifyPiece($ptr, $pieces);
         }
         // Decode the key name.
         if ($type === 'A' || $type === '"') {
             if (isset($pieces[$ptr])) {
                 $key = strtolower($this->stripQuotes($pieces[$ptr]));
             } else {
                 $key = '';
             }
             $ptr++;
         } elseif ($type === '=') {
             $ptr++;
             continue;
         } elseif ($type === -1) {
             break;
         }
         // Skip whitespace after the key name.
         while (($type = $this->classifyPiece($ptr, $pieces)) == ' ') {
             $ptr++;
         }
         // If an equal-sign follows, we need to collect a value.  Otherwise, we
         // take the key itself as the value.
         if ($type !== '=') {
             $value = $this->stripQuotes($key);
         } else {
             $ptr++;
             // Skip whitespace after the equal sign.
             while (($type = $this->classifyPiece($ptr, $pieces)) == ' ') {
                 $ptr++;
             }
             if ($type === '"') {
                 // If we get a quoted value, take that as the only value.
                 $value = $this->stripQuotes($pieces[$ptr++]);
             } elseif ($type !== -1) {
                 // If we get a non-quoted value, consume non-quoted values
                 // until we reach whitespace.
                 $value = $pieces[$ptr++];
                 while (($type = $this->classifyPiece($ptr, $pieces)) != -1 && $type != ' ') {
                     $value .= $pieces[$ptr++];
                 }
             } else {
                 $value = "";
             }
         }
         // Record this in the associative array if it's a legal public identifier name.
         // Legal *public* identifier names must *not* begin with an underscore.
         if (substr($key, 0, 1) !== '_') {
             $result[$key] = $value;
         }
         // Record this in the parameter list always.
         $params[] = ['key' => $key, 'value' => $value];
     }
     // Add the parameter list as a member of the associative array.
     $result['_params'] = $params;
     // In debugging modes, output the tag as we collected it.
     Debugger::debug("<b>Lexer::InternalDecodeTag:</b> output: ");
     Debugger::debug(htmlspecialchars(print_r($result, true)) . "<br />\n");
     // Save the resulting parameters, and return the whole shebang.
     return $result;
 }
Example #12
0
 * 
 * 11: Mikko Koski
 * 12: mikko.koski@tkk.fi
 * 13: Normaali ruokavalio
 * 14-0: Tykkään kahvista
 * 14-1: Tykkään suklaasta
 * 14-2: Tykkään pähkinästä
 * 15: Punaviini
 * ilmo_id: 56
 * user_id: 143
 * question_ids: 11,12,13,14-0,14-1,14-2,15
 */
$signupId = CommonTools::POST("signupid");
$userId = CommonTools::POST("userid");
$user = new User($signupId);
$debugger->debug("UserID: " + $userId, "save.php");
$signupGadget = new SignupGadget($signupId);
$questions = $signupGadget->getAllQuestions();
$answers = array();
// This is for debugging. It's easy to see from here the variable names that
// the form sends
$debugger->listDefinedPostAndGetVars("save.php");
foreach ($questions as $question) {
    $answer = null;
    // Checkbox is a bit more complicated
    if ($question->getType() == "checkbox") {
        $answer = parseCheckboxAnswer($question);
    } else {
        $answer = parseNormalAnswer($question);
    }
    array_push($answers, $answer);
Example #13
0
/**
 * Debugger Function
 *
 * To support a debug in any position of the code,
 * regardless the possibility of a template engine,
 * this must be text-based
 *
 * @param $mixed
 * @param $element
 */
function debug($mixed, $element = '#content')
{
    //TODO: Use Termination function
    echo Debugger::debug($mixed, $element);
    exit;
}