Example #1
0
 function ParseInt($t)
 {
     $max = 0;
     $o = "";
     $toffset = 0;
     while (strpos($t, "{", $toffset) !== false && $max < 1000) {
         $start = strpos($t, "{", $toffset) + 1;
         $end = strpos($t, "}", $start);
         $tag = substr($t, $start, $end - $start);
         $max++;
         $bits = explode(",", $tag);
         //echo "Tag : " . $bits[0] . "<br>";
         $o .= substr($t, $toffset, $start - $toffset - 1);
         $toffset = $end + 1;
         if ($bits[0] == "if" || $bits[0] == "endif") {
             //echo "Processing IF <br>";
             // find the endif. Allows nested if statements
             $open = 1;
             $ifstart = $toffset;
             while (strpos($t, "{", $toffset !== false) && $open > 0) {
                 $start = strpos($t, "{", $toffset) + 1;
                 $end = strpos($t, "}", $start);
                 $tag = substr($t, $start, $end - $start);
                 $bits2 = explode(",", $tag);
                 if ($bits2[0] == "if") {
                     $open++;
                 } else {
                     if ($bits2[0] == "endif") {
                         $open--;
                     }
                 }
                 $toffset = $end + 1;
                 //echo "If tag $tag, depth = $open<br>";
             }
             $ifend = $toffset;
             $ifcode = substr($t, $ifstart, $ifend - $ifstart - 7);
             //echo "IF Code : <pre>" . htmlentities($ifcode) . "</pre><br>";
             // match the if
             $matched = false;
             //echo "If: " . print_r($bits, true) . " - ";
             //echo $this->vars[$bits[1]] . " - ";
             if (count($bits) == 2) {
                 $var = $bits[1];
                 if (array_key_exists($var, $this->vars)) {
                     $value = $this->vars[$var];
                     if ($value) {
                         $matched = true;
                     }
                 }
             } else {
                 if (count($bits) == 3) {
                     $var = $bits[1];
                     $value = trim($bits[2], "\"'");
                     if (array_key_exists($var, $this->vars)) {
                         $varvalue = $this->vars[$var];
                         if ($varvalue == $value) {
                             $matched = true;
                         }
                     }
                 } else {
                     if (count($bits) == 4) {
                         $var = $bits[1];
                         $value = trim($bits[2], "\"'");
                         $op = $bits[3];
                         if (array_key_exists($var, $this->vars)) {
                             $varvalue = $this->vars[$var];
                             if ($op == "not") {
                                 if ($varvalue != $value) {
                                     $matched = true;
                                 }
                             } else {
                                 if ($varvalue == $value) {
                                     $matched = true;
                                 }
                             }
                         }
                     }
                 }
             }
             /*if ($matched)
             					echo "TRUE";
             				else 
             					echo "FALSE";
             
             				echo "<br>";*/
             // if IF statement is matched, parse the insides of it
             if ($matched) {
                 $o .= $this->ParseInt($ifcode);
             }
         } else {
             if ($bits[0] == "set") {
                 if (count($bits) == 3) {
                     $var = $bits[1];
                     $value = $bits[2];
                     if (is_numeric($value)) {
                         $this->vars[$var] = $value;
                     } else {
                         if ((substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") && (substr($value, strlen($value) - 1, 1) == "\"" || substr($value, strlen($value) - 1, 1) == "'")) {
                             $this->vars[$var] = trim($value, "\"'");
                         } else {
                             if (array_key_exists($value, $this->vars)) {
                                 $this->vars[$var] = $this->vars[$value];
                             } else {
                                 $this->vars[$var] = $value;
                             }
                         }
                     }
                     //echo "Setting $var to {$this->vars[$var]}<br>";
                 }
             } else {
                 if (array_key_exists($bits[0], $this->vars)) {
                     if (isset($bits[1]) && $bits[1] > 0) {
                         $ending = "";
                         if (isset($bits[2])) {
                             $ending = $bits[2];
                         }
                         $is_trimmed = false;
                         $o .= FSS_Helper::truncate($this->vars[$bits[0]], $bits[1], $is_trimmed, $ending);
                     } else {
                         $o .= $this->vars[$bits[0]];
                     }
                 }
             }
         }
     }
     $o .= substr($t, $toffset);
     if ($max == 1000) {
         exit;
     }
     return $o;
 }
Example #2
0
            $val = $this->comment['custom'][$field['id']];
            $this->comment['custom_' . $field['id']] = $val;
            $this->parser->SetVar('custom_' . $field['id'], trim($val));
            $this->parser->SetVar('custom' . $field['id'], trim($val));
            if (strlen(trim($val)) > 0) {
                $custom[] = $val;
            }
        }
    }
}
if ($this->opt_max_length > 0 && strlen($this->comment['body']) > $this->opt_max_length) {
    $randno = mt_rand(100000, 999999);
    $result = array();
    $is_trimmed = false;
    $result[] = "<div id='test_short_" . $randno . "'>";
    $result[] = FSS_Helper::truncate($this->comment['body'], $this->opt_max_length, $is_trimmed, '');
    if ($is_trimmed) {
        $result[] = "&hellip; <a href='#' onclick='expand_test(" . $randno . ");return false;'>" . JText::_("MOD_FSS_TEST_READ_MORE") . "</a><div id='test_full_" . $randno . "' style='display:none'>" . $this->comment['body'] . "</div>";
        $result[] = "</div>";
        $this->comment['body'] = trim(implode($result));
    }
}
$this->comment['body'] = str_replace("\n", "<br />", $this->comment['body']);
$this->comment['body'] = str_replace("\n", "<br />", $this->comment['body']);
$this->parser->AddVars($this->comment);
$this->parser->SetVar('divid', "fss_comment_{$this->uid}_{$this->comment['id']}");
if (count($custom) > 0) {
    $this->parser->SetVar('custom', implode(", ", $custom));
} else {
    $this->parser->SetVar('custom', "");
}