-
Notifications
You must be signed in to change notification settings - Fork 0
/
remotetypograf.php
executable file
·135 lines (110 loc) · 3.31 KB
/
remotetypograf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/*
remotetypograf.php
PHP-implementation of ArtLebedevStudio.RemoteTypograf class (web-service client)
Copyright (c) Art. Lebedev Studio | http://www.artlebedev.ru/
Typograf homepage: http://typograf.artlebedev.ru/
Web-service address: http://typograf.artlebedev.ru/webservices/typograf.asmx
WSDL-description: http://typograf.artlebedev.ru/webservices/typograf.asmx?WSDL
Default charset: UTF-8
Version: 1.0 (August 30, 2005)
Author: Andrew Shitov ([email protected])
Example:
include "remotetypograf.php";
$remoteTypograf = new RemoteTypograf();
// $remoteTypograf = new RemoteTypograf ('Windows-1251');
print $remoteTypograf->processText ('"Âû âñå åùå êîå-êàê âåðñòàåòå â "Âîðäå"? - Òîãäà ìû èäåì ê âàì!"');
*/
class RemoteTypograf
{
var $_entityType = 4;
var $_useBr = 1;
var $_useP = 1;
var $_maxNobr = 3;
var $_encoding = 'UTF-8';
var $_quotA = 'laquo raquo';
var $_quotB = 'bdquo ldquo';
function __construct ($encoding = '')
{
if ($encoding) $this->_encoding = $encoding;
}
function htmlEntities()
{
$this->_entityType = 1;
}
function xmlEntities()
{
$this->_entityType = 2;
}
function mixedEntities()
{
$this->_entityType = 4;
}
function noEntities()
{
$this->_entityType = 3;
}
function br ($value)
{
$this->_useBr = $value ? 1 : 0;
}
function p ($value)
{
$this->_useP = $value ? 1 : 0;
}
function nobr ($value)
{
$this->_maxNobr = $value ? $value : 0;
}
function quotA ($value)
{
$this->_quotA = $value;
}
function quotB ($value)
{
$this->_quotB = $value;
}
function processText ($text)
{
$text = str_replace ('&', '&', $text);
$text = str_replace ('<', '<', $text);
$text = str_replace ('>', '>', $text);
$SOAPBody = '<?xml version="1.0" encoding="' . $this->_encoding . '"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ProcessText xmlns="http://typograf.artlebedev.ru/webservices/">
<text>' . $text . '</text>
<entityType>' . $this->_entityType . '</entityType>
<useBr>' . $this->_useBr . '</useBr>
<useP>' . $this->_useP . '</useP>
<maxNobr>' . $this->_maxNobr . '</maxNobr>
<quotA>' . $this->_quotA . '</quotA>
<quotB>' . $this->_quotB . '</quotB>
</ProcessText>
</soap:Body>
</soap:Envelope>';
$host = 'typograf.artlebedev.ru';
$SOAPRequest = 'POST /webservices/typograf.asmx HTTP/1.1
Host: typograf.artlebedev.ru
Content-Type: text/xml
Content-Length: ' . strlen ($SOAPBody). '
SOAPAction: "http://typograf.artlebedev.ru/webservices/ProcessText"
'.
$SOAPBody;
$remoteTypograf = fsockopen ($host, 80);
fwrite ($remoteTypograf, $SOAPRequest);
$typografResponse = '';
while (!feof ($remoteTypograf))
{
$typografResponse .= fread ($remoteTypograf, 8192);
}
fclose ($remoteTypograf);
$startsAt = strpos ($typografResponse, '<ProcessTextResult>') + 19;
$endsAt = strpos ($typografResponse, '</ProcessTextResult>');
$typografResponse = substr ($typografResponse, $startsAt, $endsAt - $startsAt - 1);
$typografResponse = str_replace ('&', '&', $typografResponse);
$typografResponse = str_replace ('<', '<', $typografResponse);
$typografResponse = str_replace ('>', '>', $typografResponse);
return $typografResponse;
}
}