Esempio n. 1
0
switch ($function) {
    case 'getState':
        if (file_exists($file)) {
            $lines = file($file);
        }
        $log['state'] = count($lines);
        break;
    case 'send':
        $nickname = htmlentities(strip_tags($_POST['nickname']), ENT_QUOTES);
        $patterns = array("/:\\)/", "/:D/", "/:p/", "/:P/", "/:\\(/");
        $replacements = array("<img src='smiles/smile.gif'/>", "<img src='smiles/bigsmile.png'/>", "<img src='smiles/tongue.png'/>", "<img src='smiles/tongue.png'/>", "<img src='smiles/sad.png'/>");
        $reg_exUrl = "/(http|https|ftp|ftps)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(\\/\\S*)?/";
        $blankexp = "/^\n/";
        $message = htmlentities(strip_tags($_POST['message']), ENT_QUOTES);
        if (!preg_match($blankexp, $message)) {
            if (preg_match($reg_exUrl, $message, $url)) {
                $message = preg_replace($reg_exUrl, '<a href="' . $url[0] . '" target="_blank">' . $url[0] . '</a>', $message);
            }
            $message = preg_replace($patterns, $replacements, $message);
            /**
             * Parse commands & replace with responses.
             * -Allen
             */
            $command = parseCommand($file, $message);
            if (!$command) {
                fwrite(fopen($file, 'a'), "<span>" . $nickname . "</span>" . ($message = '<span class="test">' . str_replace("\n", " ", $message) . "</span>" . "\n"));
            }
        }
        break;
}
echo json_encode($log);
Esempio n. 2
0
function parseTemplate($template, $vars, $listing)
{
    global $ignore, $vars;
    if (!is_file($template)) {
        print 'No template file found (' . $template . ')';
        exit;
    }
    $handle = fopen($template, 'r');
    $inListing = false;
    $ignore = false;
    $listLines = array();
    while (!feof($handle)) {
        $line = fgets($handle);
        // Check for the end of the file list
        if ($inListing) {
            if (strcmp(trim($line), '[websvn-endlisting]') == 0) {
                $inListing = false;
                // For each item in the list
                foreach ($listing as $listvars) {
                    // Copy the value for this list item into the $vars array
                    foreach ($listvars as $id => $value) {
                        $vars[$id] = $value;
                    }
                    // Output the list item
                    foreach ($listLines as $line) {
                        if (!parseCommand($line, $vars, $handle)) {
                            if (!$ignore) {
                                print parseTags($line, $vars);
                            }
                        }
                    }
                }
            } else {
                if ($ignore == false) {
                    $listLines[] = $line;
                }
            }
        } else {
            if (parseCommand($line, $vars, $handle)) {
                continue;
            } else {
                // Check for the start of the file list
                if (strncmp(trim($line), '[websvn-startlisting]', 21) == 0) {
                    $inListing = true;
                } else {
                    if ($ignore == false) {
                        print parseTags($line, $vars);
                    }
                }
            }
        }
    }
    fclose($handle);
}
        continue;
    }
    list($name, $value) = explode("=", $array[$i]);
    if ($name == "message") {
        $message = urldecode($value);
    }
    if ($name == "id") {
        $uiid = urldecode($value);
    }
}
//$prompt = "";
$responseMessage = "";
if ($message != "" && $uiid != "") {
    $ref = "";
    $content = "";
    $cmd = parseCommand($message, $ref, $content);
    $responseMessage = "parseCommand returns [" . $cmd . "] ref=[" . $ref . "] content=[" . $content . "]";
    $con = dbopen();
    if ($cmd == "lg") {
        $responseMessage = process_list_groups($con, $uiid, 0);
    } else {
        if ($cmd == "query") {
            $responseMessage = process_query($con, $uiid, $ref, $content);
        } else {
            if ($cmd == "ans") {
                $responseMessage = process_answer($con, $uiid, $ref, $content);
            } else {
                if ($cmd == "lq") {
                    $responseMessage = process_list_queries($con, $uiid, $ref, $content);
                    // ref for groupId, content for queryId
                } else {
Esempio n. 4
0
toggle 0,0 through 999,0 would toggle the first line of 1000 lights, turning off the ones that were on, and turning on the ones that were off.
turn off 499,499 through 500,500 would turn off (or leave off) the middle four lights.
After following the instructions, how many lights are lit?
*/
$input = file(__DIR__ . '/input.txt', FILE_IGNORE_NEW_LINES);
//$input = ['turn off 499,499 through 500,500'];
$map = [];
$size = 999;
for ($x = 0; $x <= $size; $x++) {
    for ($y = 0; $y <= $size; $y++) {
        $map[$x][$y] = false;
    }
}
foreach ($input as $command) {
    var_dump($command);
    $command = parseCommand($command);
    for ($x = $command['from'][0]; $x <= $command['to'][0]; $x++) {
        for ($y = $command['from'][1]; $y <= $command['to'][1]; $y++) {
            switch ($command['command']) {
                case 'turn on':
                    $map[$x][$y] = true;
                    break;
                case 'turn off':
                    $map[$x][$y] = false;
                    break;
                case 'toggle':
                    $map[$x][$y] = !$map[$x][$y];
                    break;
            }
        }
    }
}
$uiid = -1;
$userid = "";
if ($row = $result->fetch_assoc()) {
    $uiid = $row["id"];
    $userid = $row["userid"];
    //echo "<b>$uiid $userid</b><br>Phone: $phone<br>City: $city<br>Country: $country<br><hr><br>";
}
$fh = fopen($myFile, 'a+') or die("can't open file");
fwrite($fh, date(DATE_ATOM) . " uiid=" . $uiid . ", userid=[" . $userid . "]" . PHP_EOL);
fclose($fh);
$responseMessage = bpwelcome($con, $uiid, $userid, $user_body, $user_phone, $user_city, $user_state, $user_country, $user_zip);
if (strlen($responseMessage) == 0) {
    $ref = "";
    $content = "";
    $cmd = parseCommand($user_body, $ref, $content);
    $responseMessage = "parseCommand returns [" . $cmd . "] ref=[" . $ref . "] content=[" . $content . "]";
    $con = dbopen();
    if ($cmd == "lg") {
        $responseMessage = process_list_groups($con, $uiid, 0);
    } else {
        if ($cmd == "query") {
            $responseMessage = process_query($con, $uiid, $ref, $content);
        } else {
            if ($cmd == "ans") {
                $responseMessage = process_answer($con, $uiid, $ref, $content);
            } else {
                if ($cmd == "lq") {
                    $responseMessage = process_list_queries($con, $uiid, $ref, $content);
                    // ref for groupId, content for queryId
                } else {
Esempio n. 6
0
while ($dsJob = $dsSchedules->fetch()) {
    $jobDate = null;
    $state = null;
    $type = null;
    if ($dsJob["schedule_on"]) {
        $detailsOn = parseCommand($dsJob["schedule_on"]);
        //print_r($detailsOn);
        echo $detailsOn["level"];
        if ($detailsOn["month"] != '*' && $detailsOn["day"] != '*') {
            $jobDate = $detailsOn["month"] . '/' . $detailsOn["day"] . '/' . date("y");
            $state = $detailsOn["level"];
            $type = $detailsOn["type"];
        }
    }
    if ($dsJob["schedule_off"]) {
        $detailsOff = parseCommand($dsJob["schedule_off"]);
        if ($detailsOff["month"] != '*' && $detailsOff["day"] != '*') {
            $jobDate = $detailsOff["month"] . '/' . $detailsOff["day"] . '/' . date("y");
            //$state = $detailsOff["level"];
            //$type = $detailsOff["type"];
        }
    }
    $repeats = explode(",", $dsJob["schedule_repeat"]);
    ?>
    <div class="node" id="job<?php 
    echo $dsJob["idtbl_schedules"];
    ?>
">
        <div class="nodetitle">Job</div>
        <div class="nodedetails">
            <form method="post" action="" class="form">