function main() { global $HOOKBOX_SECRET, $SCRIPT_EXTERNAL_URL, $POLL_INTERVAL, $CHANNEL_NAME; $form = array_merge($_GET, $_POST); // All callbacks we get will have the "action" form key. If we don't see // that key, then return the static page (a user is visiting this script // directly in a browser if (!in_array("action", array_keys($form))) { return static_page(); } // If we see the "action" form key, then hookbox is making a request to our // script. Check to secret to make sure the request is from hookbox. if ($form["secret"] != $HOOKBOX_SECRET) { print "[ false, { \"error\": \"Invalid secret\" } ]"; return; } switch ($form["action"]) { // Allow all users to connect; assign them a random name; case "connect": $name = uniqid(); echo "[ true, {\"name\": \"{$name}\" } ]"; break; // Only allow hookbox to create one channel, specified by $CHANNEL_NAME // Only allow hookbox to create one channel, specified by $CHANNEL_NAME case "create_channel": if ($form["channel_name"] == $CHANNEL_NAME) { $output = array(); $output[0] = true; $output[1] = array(); // our channel will acquire data by having hookbox poll this script // (and then rebroadcast it to subscribers) $output[1]["polling"] = array(); $output[1]["polling"]["url"] = $SCRIPT_EXTERNAL_URL . "?action=poll&secret=" . $HOOKBOX_SECRET; $output[1]["polling"]["interval"] = $POLL_INTERVAL; $output[1]["polling"]["mode"] = "simple"; // We'll have hookbox store 30 data points $output[1]["history_size"] = 30; $output[1]["history"] = array(); // Those 30 data points should start out pre-populated as the value 0. for ($i = 0; $i < 30; $i++) { $output[1]["history"][$i] = array(0 => "PUBLISH", 1 => array("payload" => 0)); } // returning json: [true, { "polling": { ... }, "history": [ .. ], ... } ] print_r(json_encode($output)); } else { $chan = $form["channel_name"]; echo "[ false, {\"error\": \"Cannot create channel {$chan}\"} ]"; } break; // Let anyone subscribe to that one channel // Let anyone subscribe to that one channel case "subscribe": echo "[ true, {} ]"; break; // If the server is polling then print out the server load; // If the server is polling then print out the server load; case "poll": // NOTE: If you aren't on a system with an uptime command then // try replacing this with some other integer. Perhaps // something random... $cpu_usage = explode(',', substr(exec('uptime'), -14)); print $cpu_usage[0]; break; case "destroy_channel": // By allowing destroy channel we prevent hookbox from polling this // script when their are no users watching. On the other hand, we lose // the graph's history of the last 30 values... echo "[ true, {} ]"; break; // Don't allow any other actions, such as publish // Don't allow any other actions, such as publish default: echo "[ false, {} ]"; break; } }
<ul class="nav navbar-nav"> <?php include "./include/nav_menu.php"; ?> </ul> </div> <!-- /.navbar-collapse --> </div> <!-- /.container --> </nav> <!-- Page Content --> <div class="container textarea"> <div class="row"> <div class="col-lg-12"> <?php $page_blob = static_page($db, $page); #var_dump($page_blob); #echo "<h1>".$page_blob["title"]."</h1>"; echo "<h2 class=\"text-left\">" . $page_blob["callout"] . "</h2>"; echo "<br>"; #echo "<div class=\"container text\">"; echo $page_blob["content"]; #echo "</div>"; ?> </div> </div> </div>