Example #1
0
<?php

require_once 'utils.php';
require_once 'process.php';
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
if (isset($_REQUEST["key"]) and isset($_REQUEST["format"])) {
    $key = $_REQUEST["key"];
    $format = $_REQUEST["format"];
    $conv = new ConvertBook();
    try {
        $conv->convertFromS3($key, $format);
        httpRedirect("status.php?key={$key}&format={$format}");
    } catch (Exception $e) {
        error_log("FB2PDF ERROR. Convert: " . $e->getMessage());
        httpResponseCode("400 Bad Request", "Ошибка конвертации. Пожалуйста, попробуйте ешё раз.");
    }
} else {
    if (isset($_REQUEST["url"])) {
        // redirect to the index page
        $url = $_REQUEST["url"];
        if (isset($_REQUEST["auto"])) {
            httpRedirect("uploader.php?url={$url}");
        } else {
            httpRedirect("index.php?url={$url}");
        }
    } else {
        httpResponseCode("400 Bad Request", "Missing parameter \"url\"");
    }
}
Example #2
0
    httpRedirect("status.php?key={$key}&format={$format}");
} catch (Exception $e) {
    error_log("FB2PDF ERROR. Uploader: " . $e->getMessage());
    $errCode = null;
    $errMessage = null;
    if ($e->getCode() == ConvertBook::ERR_ILLEGAL_ARG) {
        $errCode = "400 Bad Request";
        $errMessage = "Пожалуйста, укажите FB2 файл, который Вы бы хотели сконвертировать.";
    } else {
        if ($e->getCode() == ConvertBook::ERR_LOAD) {
            $errCode = "400 Bad Request";
            $errMessage = "Невозможно загрузить файл <b>{$file}</b>. Пожалуйста, убедитесь, что Вы правильно указали имя файла и попробуйте ешё раз.";
        } else {
            if ($e->getCode() == ConvertBook::ERR_FORMAT) {
                $errCode = "404 Not Found";
                $errMessage = "<b>{$file}</b> не существует или не является файлом в формате ZIP или FB2. Пожалуйста, выберите ZIP или FB2 файл и попробуйте ещё раз.";
            } else {
                if ($e->getCode() == ConvertBook::ERR_CONVERT) {
                    $errCode = "500 Internal Server Error";
                    $errMessage = "Невозможно сохранить файл <b>{$file}</b> для дальнейшей конвертации. Пожалуйста, попробуйте ешё раз.";
                } else {
                    if ($e->getCode() == ConvertBook::ERR_SIZE) {
                        $errCode = "400 Bad Request";
                        $errMessage = "Размер файла <b>{$file}</b> превышает максимально допустимый.";
                    }
                }
            }
        }
    }
    httpResponseCode($errCode, $errMessage);
}
/**
 * Called for all Newscoop errors.
 *
 * If the flag $Campsite['DEBUG'] is set to false, this function will
 * return minor errors (ie notices and warnings) without having
 * processed them.  Errors with fsockopen() are returned without being
 * processed regardless of the $Campsite['DEBUG'] flag.
 *
 * @param int    $p_number The error number.
 * @param string $p_string The error message.
 * @param string $p_file The name of the file in which the error occurred.
 * @param int    $p_line The line number in which the error occurred.
 * @return void
 */
function camp_bug_handler_main($p_number, $p_string, $p_file, $p_line)
{
    global $ADMIN_DIR;
    global $ADMIN;
    global $Campsite;
    global $g_user;
    // --- Return on unimportant errors ---
    if (!$Campsite['DEBUG']) {
        switch ($p_number) {
            case E_NOTICE:
            case E_WARNING:
            case E_USER_NOTICE:
            case E_USER_WARNING:
                return;
        }
    }
    // --- Return on coverred (with @) errors ---
    if (!error_reporting()) {
        return;
    }
    // throw exception instead of raising error
    // TODO: we should catch those exceptions on BridgeController
    /*    if (defined('APPLICATION_ENV') && APPLICATION_ENV == 'development') {
            require_once __DIR__ . '/../../library/Newscoop/Utils/Exception.php';
            $exception = new \Newscoop\Utils\Exception($p_string, $p_number);
            $exception->setFile($p_file);
            $exception->setLine($p_line);
            throw $exception;
        }*/
    // -- Return on generic errors ---
    if (preg_match('/^Undefined index:/i', $p_string)) {
        return;
    }
    if (preg_match('/^Undefined variable:/i', $p_string)) {
        return;
    }
    if (preg_match('/^Undefined offset:/i', $p_string)) {
        return;
    }
    // -- SimpleXMLElement errors ---
    if (preg_match('/^SimpleXMLElement/i', $p_string)) {
        return;
    }
    // -- Return on URL parse errors
    if (preg_match('/^parse_url/i', $p_string)) {
        return;
    }
    // -- Return on mysql connect errors ---
    if (preg_match('/^mysql_connect/i', $p_string)) {
        return;
    }
    // --- Return on socket errors ---
    if (preg_match('/^fsockopen/i', $p_string)) {
        return;
    }
    // --- Return on unlink errors ---
    if (preg_match('/^unlink/i', $p_string)) {
        return;
    }
    // --- Return on upload file errors ---
    if (preg_match('/^move_uploaded_file/i', $p_string)) {
        return;
    }
    // -- Return on getimagesize errors --
    if (preg_match('/^getimagesize/i', $p_string)) {
        return;
    }
    // -- Return on imagecreate* errors --
    if (preg_match('/^imagecreate/i', $p_string)) {
        return;
    }
    // -- Return on rmdir errors --
    if (preg_match('/^rmdir/i', $p_string)) {
        return;
    }
    // -- Return on mkdir errors --
    if (preg_match('/^mkdir/i', $p_string)) {
        return;
    }
    // -- Return on fopen errors --
    if (preg_match('/^fopen/i', $p_string)) {
        return;
    }
    // -- Return on chown errors --
    if (preg_match('/^chown/i', $p_string)) {
        return;
    }
    // -- Return on chgrp errors --
    if (preg_match('/^chgrp/i', $p_string)) {
        return;
    }
    define('IN_BUG_HANDLE', TRUE);
    if (ob_get_length() !== false) {
        // --- Don't print out the previous screen (in which the error occurred). ---
        ob_end_clean();
    }
    if (is_object($g_user)) {
        require_once $Campsite['HTML_DIR'] . "/{$ADMIN_DIR}/menu.php";
    }
    // --- If reporter doesn't exist, make one ($reporter might exist
    //     already if this script is an 'include') ---
    // Remove the code name from the version number.
    $version = explode(" ", $Campsite['VERSION']);
    $version = array_shift($version);
    if (!isset($reporter)) {
        $reporter = new BugReporter($p_number, $p_string, $p_file, $p_line, 'Newscoop', $version);
    }
    // --- Print results ---
    if (!function_exists('http_response_code')) {
        httpResponseCode(500);
    } else {
        http_response_code(500);
    }
    include dirname(__FILE__) . '/emailus.php';
    exit;
}
Example #4
0
<?php

require_once 'process.php';
require_once 'utils.php';
if (!isset($_GET["key"])) {
    httpResponseCode("400 Bad Request", "Missing parameter \"key\"");
    die;
}
$key = $_GET["key"];
$format = $_GET["format"];
$bs = new BookStatus();
try {
    $bs->checkOriginal($key);
    $status = $bs->checkConverted($key, $format);
    // generate response json
    header('Content-type: application/json');
    $response = "{\n        'status'    : '{$status}',\n        'source'    : '{$bs->fbFile}',\n        'converted' : '{$bs->convFile}',\n        'log'       : '{$bs->logFile}'\n    }";
    echo $response;
} catch (Exception $e) {
    error_log("FB2PDF ERROR. Status: " . $e->getMessage());
    httpResponseCode("400 Bad Request", $e->getMessage());
}
Example #5
0
try {
    $conv = new ConvertBook();
    $conv->convertFromUrl($_GET["url"], $_GET["format"]);
    $key = $conv->bookKey;
    $author = $conv->book->author;
    $title = $conv->book->title;
    // generate response
    header('HTTP/1.0 200 OK');
    header('Content-type: application/json');
    $response = "{\n        'key'   : '{$key}',\n        'author': '{$author}',\n        'title' : '{$title}'\n    }";
    echo $response;
} catch (Exception $e) {
    $errCode = null;
    if ($e->getCode() == ConvertBook::ERR_ILLEGAL_ARG) {
        $errCode = "400 Bad Request";
    } else {
        if ($e->getCode() == ConvertBook::ERR_LOAD) {
            $errCode = "400 Bad Request";
        } else {
            if ($e->getCode() == ConvertBook::ERR_FORMAT) {
                $errCode = "404 Not Found";
            } else {
                if ($e->getCode() == ConvertBook::ERR_CONVERT) {
                    $errCode = "500 Internal Server Error";
                }
            }
        }
    }
    error_log("FB2PDF ERROR. Status: " . $e->getMessage());
    httpResponseCode($errCode, $e->getMessage());
}