Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/patientapps_www/modules/patientapps/model/ |
Upload File : |
<?php
// simple typescript tokenizer
class pai_tokenizer {
private $tokens;
private $tokens2;
private $text;
private $c;
private $TOKENS;
private $LINES;
private $linenum;
private $linestart;
public function __construct() {
$this->tokens = ['import', 'from', 'export', 'class', 'true', 'false', 'constructor', 'for', 'return', 'this', 'if' ];
$this->tokens2 = ['[', ']', '{', '}', '(', ')', '`', '"', "'", '/*', '//', '!=', '!==', '===', '=='];
$this->Text('');
}
function skipWhiteSpace(&$p) {
while ($p < $this->c && $this->text[$p] <= ' ') {
$ch = $this->text[$p];
$p++;
if ($ch == "\n" || $ch == "\r") {
$this->linenum++;
$ch1 = ord($ch);
$ch2 = ($p < $this->c) ? ord($this->text[$p]) : 0;
if ($ch1 + $ch2 == 13 + 10) { //cr+lf or lf+cr counts as one line.
$p++;
}
$this->linestart[$this->linenum] = $p;
}
}
}
function isAlpha($p) {
$ch = strtolower($this->text[$p]);
return ($ch >= 'a' && $ch <= 'z');
}
function isNumber($p) {
$ch = $this->text[$p];
return ($ch >= '0' && $ch <= '9');
}
function getWord($p) {
if (preg_match('~^(\w+)~', substr($this->text, $p), $match)) {
return $match[1];
}
return FALSE;
}
function Text() {
if (func_num_args()) {
$this->text = func_get_arg(0);
$this->TOKENS = [];
$this->LINES = [];
$this->linenum = 0;
$this->linestart = [0 => 0];
return $this;
}
return $this->text;
}
public function Tokens() {
return $this->TOKENS;
}
protected function fetchToken(&$p) {
if ($this->isAlpha($p)) { // word tokens
$word = $this->getWord($p);
if ($word !== FALSE) {
if (in_array($word, $this->tokens)) {
$p += strlen($word);
return $word;
}
}
} elseif (!$this->isNumber($p)) { // symbol tokens
foreach($this->tokens2 as $token) {
$l = strlen($token);
if (substr($this->text, $p, $l) == $token) {
$p += $l;
return $token;
}
}
}
return FALSE;
}
function unichr($u) {
return mb_convert_encoding('&#' . intval($u) . ';', 'UTF-8', 'HTML-ENTITIES');
}
// convert unicode character to utf-8
private function _unicodable(&$p) {
$deets = substr($this->text, $p, 4);
if (preg_match('~([0-9a-f]{4})~i', $deets, $match)) {
$val = intval($match[1], 16);
$p += 4;
return $this->unichr($val);
}
return "\\u";
}
private function getString(&$p, $terminator) {
$output = '';
while($p < $this->c) {
$token = $ch = $this->text[$p]; $p++;
if ($ch == '\\') {
$ch = $this->text[$p];
$token = '\\' . $ch; $p++;
if ($token == '\\u') $ch = $this->_unicodable($p);
}
if ($token == $terminator) {
break;
}
if ($token == '\\n' || $token == '\\r' || $token == '\\t') $ch = ' ';
$output .= $ch;
}
if ($p >= $this->c) {
die("Unable find end of string: [$terminator] $output\n");
}
// echo htmlspecialchars($output) . "<br><br>\n";
return $output;
}
private function _comment(&$p, $isBlockComment) {
if ($isBlockComment) {
$q = strpos($this->text, '*/', $p);
if ($q !== FALSE) $q += 2;
// to do: count number of line breaks
} else {
$q = strpos($this->text, "\n", $p);
if ($q !== FALSE) {
$q++;
$this->linenum++; // not quite right
}
}
$p = ($q === FALSE) ? $this->c : $q;
}
public function PushToken($token) {
$c = count($this->TOKENS);
$this->TOKENS[] = $token;
$this->LINES[$c] = $this->linenum;
return $c;
}
// symbollic token
public function _processToken(&$p, $token) {
switch($token) {
case '"':
case "'":
case '`':
$this->PushToken(['type' => $token, 'token' => $this->getString($p, $token) ]);
break;
case '/*':
$this->_comment($p, TRUE);
break;
case '//':
$this->_comment($p, FALSE);
break;
default:
$this->PushToken($token);
return;
}
}
public function Tokenize($text, $break_on_construct = TRUE) {
$this->Text($text);
$p = 0;
$this->c = strlen($text);
while ($p < $this->c) {
$this->skipWhiteSpace($p);
if ($p >= $this->c) {
break;
}
$isAlphaToken = $this->isAlpha($p);
$isNumericToken = $this->isNumber($p);
$token = $this->fetchToken($p);
if ($token !== FALSE) {
if ($isAlphaToken) {
$this->PushToken($token);
// if ($token == 'constructor' && $break_on_construct) break; // end of data section
} else {
$this->_processToken($p, $token);
}
} elseif ($isAlphaToken) { // variable
$word = $this->getWord($p); $p += strlen($word);
$this->PushToken(['type' => 'variable', 'token' => $word]);
} elseif ($isNumericToken) { // number
$word = $this->getWord($p); $p += strlen($word);
$this->PushToken(['type' => 'number', 'token' => $word]);
} else {
$this->PushToken($this->text[$p]);
$p++;
}
}
return $this;
}
private function _locateDefinition($variable, $ignoreCase = TRUE) {
foreach ($this->TOKENS as $index => $info) {
if (is_array($info) && $info['type'] == 'variable') {
if ($ignoreCase) {
if (!strcasecmp($info['token'], $variable) && $this->TOKENS[$index + 1] == '=') { // assignment
return $index + 2;
}
} else {
if ($info['token'] == $variable && $this->TOKENS[$index + 1] == '=') { // assignment
return $index + 2;
}
}
}
}
return FALSE;
}
private function _processArray(&$idx) {
$output = [];
$start = $idx;
do {
$info = $this->TOKENS[$idx];
if ($info == ']') {
$idx++;
break;
}
$item = $this->_structure($idx);
$output[] = $item;
$info = $this->TOKENS[$idx];
if ($info == ',') $idx++;
} while(isset($this->TOKENS[$idx]));
if (!isset($this->TOKENS[$idx]) && $info != ']') {
$slice = array_slice($this->TOKENS, $start - 2, 20);
var_export($slice);
die("Fatal error: Missing ']'");
}
return $output;
}
private function _processObject(&$idx) {
$output = [];
do {
$info = $this->TOKENS[$idx];
if ($info == '}') {
$idx++;
break;
}
// key
if (is_array($info)) {
$key = $info['token']; // string constant, number or variable
} else {
$key = $info;
}
$idx++;
$info = $this->TOKENS[$idx]; $idx++;
if ($info != ':') break; // syntax error
$item = $this->_structure($idx);
$output[$key] = $item;
$info = $this->TOKENS[$idx];
if ($info == ',') $idx++;
} while(1);
return $output;
}
private function _simpleExpression($output, &$idx) {
do {
$info = $this->TOKENS[$idx];
if ($info != '+') break;
$idx++;
$info = $this->TOKENS[$idx];
if (is_string($info) && $info == 'this') {
$idx++;
if ($this->TOKENS[$idx] == '.') $idx++;
$info = $this->TOKENS[$idx];
if (is_array($info) && $info['type'] == 'variable') {
$output .= "\${this.{$info['token']}}";
$idx++;
}
} elseif (is_array($info) && in_array($info['type'], ['"', "'", '`']) ) { // string
$output .= $info['token'];
$idx++;
}
}
while (1);
return $output;
}
// pai-ovh: this could also be an expression '" " + this.whatever + " " + ....'
private function _structure(&$idx) {
$output = NULL;
$info = $this->TOKENS[$idx]; $idx++;
if (is_string($info)) {
switch($info) {
case '[': // array
return $this->_processArray($idx);
case '{': // object
return $this->_processObject($idx);
case 'true':
$output = true;
break;
case 'false':
$output = false;
break;
}
} elseif (is_array($info)) { // variable, number, or string
$output = $info['token'];
$info = $this->TOKENS[$idx];
if ($info == '+') {
$output = $this->_simpleExpression($output, $idx);
}
}
return $output;
}
public function GetStructure($variable, $ignoreCase = TRUE) {
$idx = $this->_locateDefinition($variable, $ignoreCase);
$output = $this->_structure($idx);
return $output;
}
function _isEqual($idx, $constant) {
$hasEqual = FALSE;
$idx++;
if (!is_string($this->TOKENS[$idx]) || $this->TOKENS[$idx] != '(') return FALSE; // not a valid if statement
$idx++;
$found = FALSE;
$c = count($this->TOKENS);
while ($idx < $c) {
$node = $this->TOKENS[$idx];
if (is_string($node)) {
if ($node == ')') {
return $found ? $idx : FALSE; // end of expression
}
if ($node == '===' || $node == '==') {
$hasEqual = TRUE;
}
} elseif ($node['type'] == '"' || $node['type'] == "'") { // FOUND!
if ($node['token'] == $constant && $hasEqual) {
$found = TRUE;
}
}
$idx++;
}
return FALSE;
}
/* search for text in this format:
var operationsName = localStorage.getItem("operations");
if(operationsName == "openReduction") {
return [
*/
public function GetSpecificProcedure($constant) {
$c = count($this->TOKENS);
foreach ($this->TOKENS as $index => $info) {
if (is_string($info) && $info == 'if') {
if (($ps = $this->_isEqual($index, $constant))) {
for($i = $ps; $i < $c; $i++) {
if (is_string($this->TOKENS[$i]) && $this->TOKENS[$i] == 'return') {
$i++;
return $this->_structure($i);
}
}
}
}
}
return FALSE;
}
// look for the definition,
// if phone or email, extract the value and add to constants
public function BuildReplacement($variable, &$constants) {
$text = $this->GetStructure($variable);
if (!is_string($text)) return '';
// extract phone or email from text - replace with {{placeholder}}, save extracted item in $constants
$needle = '';
$value = preg_match('~href="mailto:(.*?)"~ism', $text, $match) ? $match[1] : '';
if ($value != '') {
$needle = 'mailto:' . $value;
} else {
$value = preg_match('~href="tel:(.*?)"~ism', $text, $match) ? $match[1] : '';
if ($value != '') {
$needle = 'tel:' . $value;
}
}
if ($needle != '') {
$text = str_replace($needle, '{{' . $variable . '}}', $text);
$constants[$variable] = $needle;
}
return $text;
}
private function _getFollowingToken($start, $open = '(', $close = ')') {
$c = count($this->TOKENS);
$depth = 0;
while($start < $c) {
$node = $this->TOKENS[$start]; $start++;
if (is_string($node)) {
if ($node == $open) {
$depth++;
} elseif ($node == $close) {
$depth--;
}
}
if (!$depth) {
return $start;
};
}
return -1;
}
private function _reassembleText($definition, $line_start, $line_end) {
$start_position = $this->linestart[$line_start];
if (isset($this->linestart[$line_end + 1])) {
$end_position = $this->linestart[$line_end + 1];
return substr($this->text, $start_position, $end_position - $start_position);
} else {
return substr($this->text, $start_position);
}
}
public function GetFunctionDefinition($functionname) {
foreach ($this->TOKENS as $index => $info) {
if (is_array($info) && $info['type'] == 'variable') {
if ($info['token'] == $functionname) {
// skip over parameters, then what is the next token?
$next_token = $this->_getFollowingToken($index + 1);
if ($next_token >-1) {
$token = $this->TOKENS[$next_token];
// what's next - is it a '{'
if (is_string($token) && $token == '{') {
$last_token = $this->_getFollowingToken($next_token, '{', '}');
$definition = array_slice($this->TOKENS, $next_token, $last_token - $next_token);
return $this->_reassembleText($definition, $this->LINES[$next_token], $this->LINES[$last_token - 1]);
}
}
}
}
}
return FALSE;
}
public function GetOptionText($choice) {
$step = 0;
foreach ($this->TOKENS as $index => $info) {
if (!is_array($info) && $info == 'if') {
$step = 0;
} elseif (is_array($info) && ($info['type'] == '"' || $info['type'] == "'" || $info['type'] == "`")) {
if ($step == 2) {
return $info['token'];
} elseif ($info['token'] == $choice) {
$step = 1;
}
} elseif (!is_array($info) && ($info == '[' || $info == '{') && $step == 2) {
$i = $index;
return $this->_structure($i);
} elseif (!is_array($info) && $info == 'return') {
$step = 2;
}
}
return NULL;
}
private function _getItem(&$index) {
if (!isset($this->TOKENS[$index])) return FALSE;
$info = $this->TOKENS[$index]; $index++;
if (is_array($info)) {
return $info['token'];
} elseif (is_string($info)) {
return $info;
} else {
return FALSE;
}
}
// look for "var page=httpService.getPageIdentifier('aboutPregnancyContent');"
public function getPageName() {
$index = 0;
$token = $this->_getItem($index);
while ($token !== FALSE) {
$token = $this->_getItem($index);
if ($token == 'getPageIdentifier') {
$token = $this->_getItem($index);
if ($token == '(') {
return $this->_getItem($index);
}
}
};
return FALSE;
}
}