Exemplo n.º 1
0
    }
    #-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
if (Set_Error_Handler('__Error_Handler__') === FALSE) {
    exit('Не удалось установить перехват ошибок');
}
#******************************************************************************#
# НАСТРОЙКА СРЕДЫ ВЫПОЛНЕНИЯ
#******************************************************************************#
$PATH = isset($_ENV['PATH']) ? $_ENV['PATH'] : '';
#-------------------------------------------------------------------------------
$PATH = SPrintF('%s:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:%s:%s:%s', $PATH, SYSTEM_PATH, DirName(SYSTEM_PATH), DirName(DirName(SYSTEM_PATH)));
#-------------------------------------------------------------------------------
if (!PutENV(SPrintF('PATH=%s', $PATH))) {
    $GLOBALS['__MESSAGES'][] = '[JBs core]: не удалось установить переменную окружения PATH';
}
#-------------------------------------------------------------------------------
Debug(SPrintF('[JBs core]: PATH=(%s)', $PATH));
#-------------------------------------------------------------------------------
unset($PATH);
#-------------------------------------------------------------------------------
#******************************************************************************#
# ЗАГРУЗКА ХОСТА
#******************************************************************************#
$HOST_CONF = @Parse_Ini_File($Path = SPrintF('%s/hosts/%s/host.ini', SYSTEM_PATH, HOST_ID));
if (!$HOST_CONF) {
    exit(SPrintF('[JBs core]: ошибка загрузки конфигурации хоста (%s)', $Path));
}
#-------------------------------------------------------------------------------
Exemplo n.º 2
0
function HTMLDoc_CreatePDF($ModeID, $HTML, $Prefix = '/')
{
    /****************************************************************************/
    $__args_types = array('string', 'string,object', 'string');
    #-----------------------------------------------------------------------------
    $__args__ = Func_Get_Args();
    eval(FUNCTION_INIT);
    /****************************************************************************/
    if (Is_Object($HTML)) {
        #---------------------------------------------------------------------------
        $Tables = $HTML->GetByTagName('TABLE');
        #---------------------------------------------------------------------------
        for ($i = 0; $i < Count($Tables); $i++) {
            #-------------------------------------------------------------------------
            $Table =& $Tables[$i];
            #-------------------------------------------------------------------------
            switch (@$Table->Attribs['class']) {
                case 'Standard':
                    $Table->AddAttribs(array('border' => 2, 'cellspacing' => 0, 'cellpadding' => 5), TRUE);
                    break;
                default:
                    # No more...
            }
        }
        #---------------------------------------------------------------------------
        $Tds = $HTML->GetByTagName('TD');
        #---------------------------------------------------------------------------
        for ($i = 0; $i < Count($Tds); $i++) {
            #-------------------------------------------------------------------------
            $Td =& $Tds[$i];
            #-------------------------------------------------------------------------
            switch (@$Td->Attribs['class']) {
                case 'Head':
                    $Td->AddAttribs(array('bgcolor' => '#ADC1F0'), TRUE);
                    break;
                case 'Separator':
                    $Td->AddAttribs(array('bgcolor' => '#EAEAEA'), TRUE);
                    break;
                default:
                    # No more...
            }
        }
        #---------------------------------------------------------------------------
        $Imgs = $HTML->GetByTagName('IMG');
        #---------------------------------------------------------------------------
        for ($i = 0; $i < Count($Imgs); $i++) {
            #-------------------------------------------------------------------------
            $Img =& $Imgs[$i];
            #-------------------------------------------------------------------------
            $Img->AddAttribs(array('src' => SPrintF('%s/%s', $Prefix, $Img->Attribs['src'])), TRUE);
        }
        #---------------------------------------------------------------------------
        $HTML = $HTML->Build();
    }
    #-----------------------------------------------------------------------------
    $Config = Config();
    #-----------------------------------------------------------------------------
    $Settings = $Config['HTMLDOC'];
    #-----------------------------------------------------------------------------
    $Modes = $Settings['Modes'];
    #-----------------------------------------------------------------------------
    $Mode = isset($Modes[$ModeID]) ? $Modes[$ModeID] : $ModeID;
    #-----------------------------------------------------------------------------
    $Tmp = System_Element('tmp');
    if (Is_Error($Tmp)) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: временная папка не найдена');
    }
    #-----------------------------------------------------------------------------
    $Logs = SPrintF('%s/logs', $Tmp);
    #-----------------------------------------------------------------------------
    if (!File_Exists($Logs)) {
        #---------------------------------------------------------------------------
        if (!@MkDir($Logs, 0777, TRUE)) {
            return ERROR | @Trigger_Error(500);
        }
    }
    #-----------------------------------------------------------------------------
    $HTML = @Mb_Convert_Encoding($HTML, $Settings['ConvertToCharset']);
    if (!$HTML) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: не удалось преобразовать кодировку');
    }
    #-----------------------------------------------------------------------------
    $UniqID = UniqID('HTMLDOC');
    #-----------------------------------------------------------------------------
    $File = IO_Write($Path = SPrintF('%s/%s', $Tmp, $UniqID), $HTML);
    Debug($File);
    if (Is_Error($File)) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: не удалось создать временный файл');
    }
    #-----------------------------------------------------------------------------
    $Command = SPrintF('htmldoc %s %s', $Mode, $Path);
    #-----------------------------------------------------------------------------
    Debug($Command);
    #-----------------------------------------------------------------------------
    if (!PutENV('HTMLDOC_NOCGI=1')) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: не удалось установить переменную окружения HTMLDOC_NOCGI');
    }
    #-----------------------------------------------------------------------------
    $HTMLDOC = @Proc_Open($Command, array(array('pipe', 'r'), array('pipe', 'w'), array('file', $Log = SPrintF('%s/HTMLDOC.log', $Logs), 'a')), $Pipes);
    if (!Is_Resource($HTMLDOC)) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: не удалось открыть процесс');
    }
    #-----------------------------------------------------------------------------
    $StdOut =& $Pipes[1];
    #-----------------------------------------------------------------------------
    $Result = '';
    #-----------------------------------------------------------------------------
    while (!Feof($StdOut)) {
        $Result .= FRead($StdOut, 1024);
    }
    #-----------------------------------------------------------------------------
    Proc_Close($HTMLDOC);
    #-----------------------------------------------------------------------------
    if (!UnLink($Path)) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: не удалось удалить временный файл');
    }
    #-----------------------------------------------------------------------------
    if (!$Result) {
        return ERROR | @Trigger_Error(SPrintF('[HTMLDoc_CreatePDF]: ошибка формирования PDF, смотрите (%s)', $Log));
    }
    #-----------------------------------------------------------------------------
    return $Result;
}