예제 #1
0
<?php

if (!empty($_POST)) {
    session_start();
    if (isset($_POST['form']) && (!isset($_SESSION['form']) || $_SESSION['form'] !== $_POST['form'])) {
        $_SESSION['form'] = $_POST['form'];
        if (!empty($_POST['name']) && !empty($_POST['id']) && !empty($_POST['type'])) {
            $name = $_POST['name'];
            $id = $_POST['id'];
            $type = $_POST['type'] === 'user' ? 'user' : 'channel';
            if (strlen($name) <= 20 && strlen($id) <= 48) {
                $ws = new Scraper();
                if ($ws->addChannel($id, 'new', $type)) {
                    $ws->fetch();
                    $response = $ws->fetchChannel($id);
                    unset($ws);
                    if (!empty($response)) {
                        $db = new Datastore();
                        $query = 'INSERT INTO channels VALUES
                                  (
                                      NULL,
                                      ?,
                                      ?,
                                      ?
                                   )';
                        $options = array('sss', &$name, &$id, &$type);
                        $db->query($query, $options);
                        unset($db);
                        echo 'Successfully added channel ' . htmlentities($name);
                    } else {
                        echo 'Channel ' . htmlentities($name) . ' does not exist or the page is down';