Version Notes
1.3.12
* vb-to-magento logout issues were fixed in vb product
* vb product was removed from the package, you're welcome to aitoc.com
1.3.11 - notifications system included
0.3.11 - initial stable release
Download this release
Release Info
Developer | Magento Core Team |
Extension | Aitoc_Aitvbulletin |
Version | 1.3.12 |
Comparing to | |
See all releases |
Code changes from version 1.3.11 to 1.3.12
- app/code/local/Aitoc/Aitvbulletin/etc/config.xml +1 -1
- package.xml +11 -5
- vbulletin_product/vbulletin_import/Aitoc MagentoVB Lite.xml +0 -172
- vbulletin_product/vbulletin_upload/aitmagentovb.php +0 -134
- vbulletin_product/vbulletin_upload/includes/class_aitmagentovb.php +0 -259
- vbulletin_product/vbulletin_upload/includes/class_aitzend.php +0 -1679
app/code/local/Aitoc/Aitvbulletin/etc/config.xml
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<config>
|
4 |
<modules>
|
5 |
<Aitoc_Aitvbulletin>
|
6 |
-
<version>
|
7 |
</Aitoc_Aitvbulletin>
|
8 |
</modules>
|
9 |
|
3 |
<config>
|
4 |
<modules>
|
5 |
<Aitoc_Aitvbulletin>
|
6 |
+
<version>1.3.12</version>
|
7 |
</Aitoc_Aitvbulletin>
|
8 |
</modules>
|
9 |
|
package.xml
CHANGED
@@ -1,18 +1,24 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Aitoc_Aitvbulletin</name>
|
4 |
-
<version>1.3.
|
5 |
<stability>stable</stability>
|
6 |
<license>OSL v3.0</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>vBulletin Integration Lite</summary>
|
10 |
<description>vBulletin Integration Lite</description>
|
11 |
-
<notes>1.3.
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
<authors><author><name>AITOC Inc.</name><user>auto-converted</user><email>magsupport@aitoc.com</email></author></authors>
|
13 |
-
<date>2009-11-
|
14 |
-
<time>15:
|
15 |
-
<contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="aitvbulletin.xml" hash="de017b0a4a96fae6acdc123a82a1e8b8"/></dir><dir name="template"><dir name="aitvbulletin"><dir name="vbserver"><file name="edit.phtml" hash="9489aeaff76338c949951262b90aaae4"/><file name="js.phtml" hash="ed1afcb1ff9daca0a6da318fb7668341"/></dir><file name="aitoc_news.phtml" hash="b4747f0c6876b62413cd3aa37d8f6ef2"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="aitvbulletin.xml" hash="380748ff547119d19ea360996935bd7c"/></dir><dir name="template"><dir name="aitvbulletin"><dir name="customer"><file name="forum.phtml" hash="3a946c44d82ae0acb74b3011053efaec"/></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><file name="aitvbulletin.css" hash="52c2b2ce71b35bfdcb64dc6909b6301a"/></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="css"><file name="aitvbulletin.css" hash="65788bd84d8c88833d4a649fea9ac7db"/></dir></dir></dir></dir></target><target name="magelocal"><dir name="Aitoc"><dir name="Aitvbulletin"><dir name="Block"><dir name="Account"><file name="Forum.php" hash="d05d46902fc451fa6b727bf0b25007fc"/><file name="Logout.php" hash="b9fa0831933805d6b9c4655454fc348c"/></dir><dir name="Admin"><dir name="Vbserver"><dir name="Edit"><file name="Form.php" hash="9a54e86df8d4d7e4270a493a09316bc5"/></dir><file name="Edit.php" hash="0c9ca6688eb5ada387ea5e0138b2ae25"/></dir><file name="News.php" hash="f8a8320f2c09a5461f6b34c7a291c1e6"/></dir><dir name="Config"><file name="FormFieldset.php" hash="40542e7fe989c52cb9be66cf30e2eb75"/></dir><dir name="Rewrite"><file name="FrontPageHtml.data.php" hash="f55f995f434d8691c7b4b6929ac977f1"/><file name="FrontPageHtml.php" hash="f55f995f434d8691c7b4b6929ac977f1"/></dir></dir><dir name="controllers"><dir name="Admin"><file name="VbserverController.php" hash="227d8e99e62b72937a410875e368079d"/></dir><file name="AccountController.php" hash="51cc63ad2ef19f917c94353831185a6a"/><file name="ProxyController.php" hash="e7ffc3942b8d4f832c6da476f59b958a"/></dir><dir name="etc"><file name="config.xml" hash="
|
16 |
<compatible/>
|
17 |
<dependencies/>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Aitoc_Aitvbulletin</name>
|
4 |
+
<version>1.3.12</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>OSL v3.0</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>vBulletin Integration Lite</summary>
|
10 |
<description>vBulletin Integration Lite</description>
|
11 |
+
<notes>1.3.12
|
12 |
+
* vb-to-magento logout issues were fixed in vb product
|
13 |
+
* vb product was removed from the package, you're welcome to aitoc.com
|
14 |
+
|
15 |
+
1.3.11 - notifications system included
|
16 |
+
|
17 |
+
0.3.11 - initial stable release</notes>
|
18 |
<authors><author><name>AITOC Inc.</name><user>auto-converted</user><email>magsupport@aitoc.com</email></author></authors>
|
19 |
+
<date>2009-11-25</date>
|
20 |
+
<time>15:02:23</time>
|
21 |
+
<contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="aitvbulletin.xml" hash="de017b0a4a96fae6acdc123a82a1e8b8"/></dir><dir name="template"><dir name="aitvbulletin"><dir name="vbserver"><file name="edit.phtml" hash="9489aeaff76338c949951262b90aaae4"/><file name="js.phtml" hash="ed1afcb1ff9daca0a6da318fb7668341"/></dir><file name="aitoc_news.phtml" hash="b4747f0c6876b62413cd3aa37d8f6ef2"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="aitvbulletin.xml" hash="380748ff547119d19ea360996935bd7c"/></dir><dir name="template"><dir name="aitvbulletin"><dir name="customer"><file name="forum.phtml" hash="3a946c44d82ae0acb74b3011053efaec"/></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><file name="aitvbulletin.css" hash="52c2b2ce71b35bfdcb64dc6909b6301a"/></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="css"><file name="aitvbulletin.css" hash="65788bd84d8c88833d4a649fea9ac7db"/></dir></dir></dir></dir></target><target name="magelocal"><dir name="Aitoc"><dir name="Aitvbulletin"><dir name="Block"><dir name="Account"><file name="Forum.php" hash="d05d46902fc451fa6b727bf0b25007fc"/><file name="Logout.php" hash="b9fa0831933805d6b9c4655454fc348c"/></dir><dir name="Admin"><dir name="Vbserver"><dir name="Edit"><file name="Form.php" hash="9a54e86df8d4d7e4270a493a09316bc5"/></dir><file name="Edit.php" hash="0c9ca6688eb5ada387ea5e0138b2ae25"/></dir><file name="News.php" hash="f8a8320f2c09a5461f6b34c7a291c1e6"/></dir><dir name="Config"><file name="FormFieldset.php" hash="40542e7fe989c52cb9be66cf30e2eb75"/></dir><dir name="Rewrite"><file name="FrontPageHtml.data.php" hash="f55f995f434d8691c7b4b6929ac977f1"/><file name="FrontPageHtml.php" hash="f55f995f434d8691c7b4b6929ac977f1"/></dir></dir><dir name="controllers"><dir name="Admin"><file name="VbserverController.php" hash="227d8e99e62b72937a410875e368079d"/></dir><file name="AccountController.php" hash="51cc63ad2ef19f917c94353831185a6a"/><file name="ProxyController.php" hash="e7ffc3942b8d4f832c6da476f59b958a"/></dir><dir name="etc"><file name="config.xml" hash="71973153ceab4e1305919286575e79d0"/><file name="system.xml" hash="8a3b3d5973ca04fb74b99aaf0be84d8c"/></dir><dir name="Helper"><file name="Data.php" hash="428a8e8b0dfcadcdc0337df173160e69"/></dir><dir name="Model"><dir name="Config"><file name="BackendForum.php" hash="d05248f76e9d6647106e347f5a2e7425"/><file name="SourceDbtype.php" hash="cdc526f5f2d9c2300a50741e0aa6f79b"/><file name="SourceForum.php" hash="be76097fccc73715eca57ee312a4d964"/></dir><dir name="Mysql4"><file name="Setup.php" hash="1e1c060d123baa160f34344c635e0bb2"/></dir><dir name="Notification"><file name="Abstract.php" hash="bc96d7b27bbf7093bf331808f60d96fc"/><file name="News.php" hash="92c52193deef455bbce2d588b107e066"/><file name="Notifications.php" hash="d36f130ed2ccf5e213a6b857f595b7dc"/><file name="Observer.php" hash="18d1797a8fb490b910825fb6eba5420b"/><file name="Service.php" hash="80a307a3aa4cc75a2225bfa83bb04c35"/></dir><dir name="Rewrite"><file name="FrontCustomer.data.php" hash="1243986eba9d075d931cbbd75ee87a27"/><file name="FrontCustomer.php" hash="1243986eba9d075d931cbbd75ee87a27"/></dir><dir name="Vbulletin"><dir name="Mysql4"><dir name="Collection"><file name="Abstract.php" hash="ed7b054368f44b51fb632a046479f1ed"/></dir><dir name="Hash"><file name="Collection.php" hash="2020d19a2a6ccc6d4c4d51e297daece4"/></dir><dir name="User"><file name="Collection.php" hash="0134e12a71f26da56e1c916387119196"/></dir><file name="Abstract.php" hash="362b20169cecc28a5c595103cbbb260a"/><file name="Hash.php" hash="0b41311285b8841ca8d8ffd9cdcd1f95"/><file name="User.php" hash="dda0927f6ab2a6aff6cdff34a2a75614"/></dir><file name="Abstract.php" hash="9ea20ad9b6597a12c6af89156da3b422"/><file name="Hash.php" hash="2c0339fab2cd0045155cfdd17f7d01db"/><file name="User.php" hash="862af11617928ee071ddaba6d8e820bb"/></dir><file name="Curl.php" hash="3c960a9b133da3b38f08f2cf2fea37d1"/><file name="Exception.php" hash="7f71f3df1b41a464ad9fb0de07d9de18"/><file name="Observer.php" hash="a52afff6cbc11406370b9141a3425db3"/><file name="Session.php" hash="03f9a0164698015cfed549e2cee9d45b"/><file name="Vbserver.php" hash="2399f684238f8b4bd31d436874f3adaa"/></dir><dir name="sql"><dir name="aitvbulletin_setup"><file name="mysql4-install-1.3.11.php" hash="3b36568577a6a305b96a1c38766cd521"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Aitoc_Aitvbulletin.xml" hash="2831023ea95a40158ef7bd3f079ec465"/></dir></target></contents>
|
22 |
<compatible/>
|
23 |
<dependencies/>
|
24 |
</package>
|
vbulletin_product/vbulletin_import/Aitoc MagentoVB Lite.xml
DELETED
@@ -1,172 +0,0 @@
|
|
1 |
-
<?xml version="1.0" encoding="ISO-8859-1"?>
|
2 |
-
|
3 |
-
<product productid="aitmagentovb" active="1">
|
4 |
-
<title>AITOC MagentoVB Lite Bridge</title>
|
5 |
-
<description>A bridge with your Magento website (lite version)</description>
|
6 |
-
<version>0.3.11</version>
|
7 |
-
<url><![CDATA[http://www.aitoc.com/]]></url>
|
8 |
-
<versioncheckurl />
|
9 |
-
<dependencies></dependencies>
|
10 |
-
<codes>
|
11 |
-
<code version="*">
|
12 |
-
<installcode><![CDATA[
|
13 |
-
$sql = '
|
14 |
-
CREATE TABLE IF NOT EXISTS `'.TABLE_PREFIX.'aitmagentovb_hash` (
|
15 |
-
`hashid` int(10) unsigned NOT NULL auto_increment,
|
16 |
-
`hash` varchar(36) NOT NULL,
|
17 |
-
`validthru` datetime NOT NULL,
|
18 |
-
`created_by` ENUM( "vbul", "mage" ) NOT NULL,
|
19 |
-
PRIMARY KEY (`hashid`),
|
20 |
-
KEY `validthru` (`validthru`),
|
21 |
-
KEY `hash` (`hash`)
|
22 |
-
) ENGINE=MyISAM
|
23 |
-
';
|
24 |
-
$vbulletin->db->query_write($sql);
|
25 |
-
]]></installcode>
|
26 |
-
<uninstallcode><![CDATA[
|
27 |
-
$vbulletin->db->query_first('DROP TABLE IF EXISTS `'.TABLE_PREFIX.'aitmagentovb_hash`');
|
28 |
-
]]></uninstallcode>
|
29 |
-
</code>
|
30 |
-
</codes>
|
31 |
-
|
32 |
-
<templates>
|
33 |
-
<template name="aitmagentovb_auth_image" templatetype="template" date="1250000000" username="Aitoc" version="1.0.0"><![CDATA[
|
34 |
-
|
35 |
-
<div style="position: absolute !important; top: -10px !important; left: -10px !important; width: 1px !important; height: 1px !important; ">
|
36 |
-
<img src="#aitmagentovbUrl" width="1" height="1" alt="" border="0" />
|
37 |
-
</div>
|
38 |
-
|
39 |
-
]]></template>
|
40 |
-
</templates>
|
41 |
-
|
42 |
-
<plugins>
|
43 |
-
<plugin active="1" executionorder="5">
|
44 |
-
<title>Template Cache</title>
|
45 |
-
<hookname>cache_templates</hookname>
|
46 |
-
<phpcode><![CDATA[
|
47 |
-
|
48 |
-
$globaltemplates = array_merge($globaltemplates, array('aitmagentovb_bbcode_quote','aitmagentovb_auth_image',));
|
49 |
-
|
50 |
-
]]></phpcode>
|
51 |
-
</plugin>
|
52 |
-
<plugin active="1" executionorder="5">
|
53 |
-
<title>Parse Templates</title>
|
54 |
-
<hookname>parse_templates</hookname>
|
55 |
-
<phpcode><![CDATA[
|
56 |
-
|
57 |
-
if ($vbulletin->userinfo['userid'] AND 2 == $vbulletin->userinfo['usergroupid'] AND $show['member'])
|
58 |
-
{
|
59 |
-
$aitmagentovbVars = array(
|
60 |
-
'do' => 'login',
|
61 |
-
'u' => $vbulletin->userinfo['userid'],
|
62 |
-
);
|
63 |
-
$aitmagentovbUrl = Aitmagentovb::getProxyUrl($aitmagentovbVars, null, $aitmagentovbVars['do'].$aitmagentovbVars['u']);
|
64 |
-
|
65 |
-
$vbulletin->templatecache['navbar'] .= str_replace('#aitmagentovbUrl', $aitmagentovbUrl, $vbulletin->templatecache['aitmagentovb_auth_image']);
|
66 |
-
}
|
67 |
-
|
68 |
-
]]></phpcode>
|
69 |
-
</plugin>
|
70 |
-
<plugin active="1" executionorder="5">
|
71 |
-
<title>INIT Startup</title>
|
72 |
-
<hookname>init_startup</hookname>
|
73 |
-
<phpcode><![CDATA[
|
74 |
-
|
75 |
-
require_once(DIR . '/includes/class_aitmagentovb.php');
|
76 |
-
Aitmagentovb::cleanHashes();
|
77 |
-
|
78 |
-
]]></phpcode>
|
79 |
-
</plugin>
|
80 |
-
|
81 |
-
<plugin active="1" executionorder="5">
|
82 |
-
<title>Login Process</title>
|
83 |
-
<hookname>login_process</hookname>
|
84 |
-
<phpcode><![CDATA[
|
85 |
-
|
86 |
-
$aitmagentovbVars = array(
|
87 |
-
'do' => 'login',
|
88 |
-
'u' => $vbulletin->userinfo['userid'],
|
89 |
-
);
|
90 |
-
$aitmagentovbUrl = Aitmagentovb::getProxyUrl($aitmagentovbVars, null, $aitmagentovbVars['do'].$aitmagentovbVars['u']);
|
91 |
-
|
92 |
-
$vbulletin->templatecache['navbar'] .= str_replace('#aitmagentovbUrl', $aitmagentovbUrl, $vbulletin->templatecache['aitmagentovb_auth_image']);
|
93 |
-
|
94 |
-
]]></phpcode>
|
95 |
-
</plugin>
|
96 |
-
|
97 |
-
<plugin active="1" executionorder="5">
|
98 |
-
<title>Logout Process</title>
|
99 |
-
<hookname>logout_process</hookname>
|
100 |
-
<phpcode><![CDATA[
|
101 |
-
|
102 |
-
$aitmagentovbVars = array(
|
103 |
-
'do' => 'logout',
|
104 |
-
);
|
105 |
-
$aitmagentovbUrl = Aitmagentovb::getProxyUrl($aitmagentovbVars, null, $aitmagentovbVars['do']);
|
106 |
-
|
107 |
-
$vbulletin->templatecache['navbar'] .= str_replace('#aitmagentovbUrl', $aitmagentovbUrl, $vbulletin->templatecache['aitmagentovb_auth_image']);
|
108 |
-
|
109 |
-
]]></phpcode>
|
110 |
-
</plugin>
|
111 |
-
|
112 |
-
<plugin active="1" executionorder="5">
|
113 |
-
<title>User delete by Admin</title>
|
114 |
-
<hookname>userdata_delete</hookname>
|
115 |
-
<phpcode><![CDATA[
|
116 |
-
|
117 |
-
require_once(DIR . '/includes/class_aitmagentovb.php');
|
118 |
-
require_once(DIR . '/includes/class_aitzend.php');
|
119 |
-
$aVars = array(
|
120 |
-
'do' => 'unlink',
|
121 |
-
'u' => $this->existing['userid'],
|
122 |
-
);
|
123 |
-
try
|
124 |
-
{
|
125 |
-
$aResponce = Aitmagentovb::curlWrite(
|
126 |
-
'POST',
|
127 |
-
Aitmagentovb::getProxyUrl($aVars, null, $aVars['do'].$aVars['u']),
|
128 |
-
'1.1',
|
129 |
-
array(),
|
130 |
-
Aitmagentovb::mergeRequestVars($aVars, true)
|
131 |
-
);
|
132 |
-
} catch (Exception $e) { }
|
133 |
-
|
134 |
-
]]></phpcode>
|
135 |
-
</plugin>
|
136 |
-
</plugins>
|
137 |
-
|
138 |
-
<phrases>
|
139 |
-
<phrasetype name="vBulletin Settings" fieldname="vbsettings">
|
140 |
-
<phrase name="setting_aitmagentovb_apikey_title" date="0" username="Aitoc" version=""><![CDATA[Module API key]]></phrase>
|
141 |
-
<phrase name="setting_aitmagentovb_apikey_desc" date="0" username="Aitoc" version=""><![CDATA[use it to create a connection in Magento Admin "System > vBulletin Connection"]]></phrase>
|
142 |
-
|
143 |
-
<phrase name="setting_aitmagentovb_url_title" date="0" username="Aitoc" version=""><![CDATA[Your Magento URL]]></phrase>
|
144 |
-
<phrase name="setting_aitmagentovb_url_desc" date="0" username="Aitoc" version=""><![CDATA[starting with http://]]></phrase>
|
145 |
-
|
146 |
-
<phrase name="settinggroup_aitmagentovb" date="0" username="Aitoc" version=""><![CDATA[AITOC MagentoVB Lite Settings]]></phrase>
|
147 |
-
</phrasetype>
|
148 |
-
</phrases>
|
149 |
-
|
150 |
-
<options>
|
151 |
-
<settinggroup name="aitmagentovb" displayorder="65535">
|
152 |
-
<setting varname="aitmagentovb_apikey" displayorder="10">
|
153 |
-
<datatype>free</datatype>
|
154 |
-
<defaultvalue><![CDATA[changeme]]></defaultvalue>
|
155 |
-
</setting>
|
156 |
-
<setting varname="aitmagentovb_url" displayorder="30">
|
157 |
-
<datatype>free</datatype>
|
158 |
-
<defaultvalue><![CDATA[]]></defaultvalue>
|
159 |
-
</setting>
|
160 |
-
</settinggroup>
|
161 |
-
</options>
|
162 |
-
|
163 |
-
<helptopics>
|
164 |
-
</helptopics>
|
165 |
-
|
166 |
-
<cronentries>
|
167 |
-
</cronentries>
|
168 |
-
|
169 |
-
<faqentries>
|
170 |
-
</faqentries>
|
171 |
-
|
172 |
-
</product>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vbulletin_product/vbulletin_upload/aitmagentovb.php
DELETED
@@ -1,134 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* @copyright Copyright (c) 2009 AITOC, Inc.
|
4 |
-
*/
|
5 |
-
|
6 |
-
error_reporting(E_ALL & ~E_NOTICE);
|
7 |
-
|
8 |
-
define('THIS_SCRIPT', 'aitmagentovb');
|
9 |
-
|
10 |
-
header('P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
|
11 |
-
//header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
|
12 |
-
|
13 |
-
require_once('./global.php');
|
14 |
-
require_once(DIR . '/includes/class_aitmagentovb.php');
|
15 |
-
require_once(DIR . '/includes/class_aitzend.php');
|
16 |
-
|
17 |
-
$vbulletin->input->clean_array_gpc('r', array(
|
18 |
-
'h' => TYPE_STR,
|
19 |
-
));
|
20 |
-
|
21 |
-
if (empty($_REQUEST['do']))
|
22 |
-
{
|
23 |
-
exec_header_redirect($vbulletin->options['forumhome'] . '.php');
|
24 |
-
}
|
25 |
-
|
26 |
-
if ($_REQUEST['do'] == 'login')
|
27 |
-
{
|
28 |
-
/**
|
29 |
-
* Log in user by userid
|
30 |
-
* $_REQUEST['userid'] - userid
|
31 |
-
*/
|
32 |
-
$vbulletin->input->clean_array_gpc('r', array(
|
33 |
-
'userid' => TYPE_INT,
|
34 |
-
));
|
35 |
-
|
36 |
-
if ($vbulletin->GPC['userid'] AND
|
37 |
-
Aitmagentovb::isValidApikeyHash($vbulletin->GPC['h'], $_REQUEST['do'] . $vbulletin->GPC['userid']) AND
|
38 |
-
$loguser = fetch_userinfo($vbulletin->GPC['userid']) AND
|
39 |
-
$vbulletin->userinfo['userid'] != $loguser['userid'] ) // no need to login if user is already authorized
|
40 |
-
{
|
41 |
-
require_once(DIR . '/includes/functions_login.php');
|
42 |
-
|
43 |
-
exec_unstrike_user($loguser['username']);
|
44 |
-
|
45 |
-
$vbulletin->userinfo['userid'] = $loguser['userid'];
|
46 |
-
process_new_login('', false, '');
|
47 |
-
|
48 |
-
exec_shut_down();
|
49 |
-
}
|
50 |
-
|
51 |
-
Aitmagentovb::outputBlankGif();
|
52 |
-
}
|
53 |
-
elseif ($_REQUEST['do'] == 'logout')
|
54 |
-
{
|
55 |
-
/**
|
56 |
-
* Log out user by userid
|
57 |
-
* $_REQUEST['userid'] - userid
|
58 |
-
*/
|
59 |
-
$vbulletin->input->clean_array_gpc('r', array(
|
60 |
-
'userid' => TYPE_INT,
|
61 |
-
));
|
62 |
-
|
63 |
-
if ($vbulletin->GPC['userid'] == $vbulletin->userinfo['userid'] AND
|
64 |
-
Aitmagentovb::isValidApikeyHash($vbulletin->GPC['h'], $_REQUEST['do'] . $vbulletin->GPC['userid']) )
|
65 |
-
{
|
66 |
-
require_once(DIR . '/includes/functions_login.php');
|
67 |
-
|
68 |
-
process_logout();
|
69 |
-
|
70 |
-
exec_shut_down();
|
71 |
-
}
|
72 |
-
|
73 |
-
Aitmagentovb::outputBlankGif();
|
74 |
-
}
|
75 |
-
elseif ($_REQUEST['do'] == 'verify')
|
76 |
-
{
|
77 |
-
/**
|
78 |
-
* Verify user
|
79 |
-
* $_POST['username'] - forum username
|
80 |
-
* $_POST['password_md5'] - password md5 hash
|
81 |
-
* @since 0.3.0
|
82 |
-
*/
|
83 |
-
$vbulletin->input->clean_array_gpc('p', array(
|
84 |
-
'username' => TYPE_STR,
|
85 |
-
'password_md5' => TYPE_STR,
|
86 |
-
));
|
87 |
-
|
88 |
-
if ($vbulletin->GPC['username'] AND
|
89 |
-
$vbulletin->GPC['password_md5'] AND
|
90 |
-
Aitmagentovb::isValidApikeyHash($vbulletin->GPC['h'], $_REQUEST['do'] . $vbulletin->GPC['username']) )
|
91 |
-
{
|
92 |
-
require_once(DIR . '/includes/functions_login.php');
|
93 |
-
|
94 |
-
if (!verify_authentication($vbulletin->GPC['username'], '', $vbulletin->GPC['password_md5'], '', false, false))
|
95 |
-
{
|
96 |
-
exec_header_redirect($vbulletin->options['forumhome'] . '.php');
|
97 |
-
}
|
98 |
-
|
99 |
-
$aitmagentovbResult = array();
|
100 |
-
$aitmagentovbResult['userid'] = $vbulletin->userinfo['userid'];
|
101 |
-
$aitmagentovbResult['email'] = $vbulletin->userinfo['email'];
|
102 |
-
$aitmagentovbResult['done'] = 'verify';
|
103 |
-
|
104 |
-
Aitmagentovb::outputJsonResult($aitmagentovbResult);
|
105 |
-
|
106 |
-
exec_shut_down();
|
107 |
-
}
|
108 |
-
else
|
109 |
-
{
|
110 |
-
exec_header_redirect($vbulletin->options['forumhome'] . '.php');
|
111 |
-
}
|
112 |
-
}
|
113 |
-
else if ($_REQUEST['do'] == 'ping')
|
114 |
-
{
|
115 |
-
$aitmagentovbResult = array('THIS_SCRIPT' => THIS_SCRIPT);
|
116 |
-
|
117 |
-
Aitmagentovb::outputJsonResult($aitmagentovbResult, true);
|
118 |
-
}
|
119 |
-
else if ($_POST['do'] == 'options')
|
120 |
-
{
|
121 |
-
if (Aitmagentovb::isValidApikeyHash($vbulletin->GPC['h'], $_POST['do']) )
|
122 |
-
{
|
123 |
-
$aitmagentovbResult = $vbulletin->options;
|
124 |
-
$aitmagentovbResult['bf_misc'] = $vbulletin->bf_misc; /** @since 0.2.2 */
|
125 |
-
$aitmagentovbResult['bf_ugp'] = $vbulletin->bf_ugp; /** @since 0.3.0 */
|
126 |
-
$aitmagentovbResult['done'] = 'options';
|
127 |
-
|
128 |
-
Aitmagentovb::outputJsonResult($aitmagentovbResult, true);
|
129 |
-
}
|
130 |
-
else
|
131 |
-
{
|
132 |
-
exec_header_redirect($vbulletin->options['forumhome'] . '.php');
|
133 |
-
}
|
134 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vbulletin_product/vbulletin_upload/includes/class_aitmagentovb.php
DELETED
@@ -1,259 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* @copyright Copyright (c) 2009 AITOC, Inc.
|
4 |
-
*/
|
5 |
-
|
6 |
-
class Aitmagentovb
|
7 |
-
{
|
8 |
-
const CURL_TIMEOUT_SEC = 10;
|
9 |
-
const APIKEY_HASH_LIFETIME = 20; // in seconds, see storeHashLifetime()
|
10 |
-
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Validate hash
|
14 |
-
*
|
15 |
-
* @param string $hash
|
16 |
-
* @param string $secureSalt
|
17 |
-
* @return boolean
|
18 |
-
*/
|
19 |
-
static public function isValidApikeyHash($hash, $secureSalt)
|
20 |
-
{
|
21 |
-
global $vbulletin;
|
22 |
-
$hash = rawurldecode($hash);
|
23 |
-
|
24 |
-
// $randomSalt - random
|
25 |
-
// $key = md5( md5($apikey.$secureSalt) . $randomSalt )
|
26 |
-
// $hash = "$key:$randomSalt"
|
27 |
-
|
28 |
-
if (!$hash OR !$secureSalt OR !$vbulletin->options['aitmagentovb_apikey']) return false;
|
29 |
-
|
30 |
-
$hashArr = explode(':', $hash);
|
31 |
-
if (count($hashArr) == 2)
|
32 |
-
{
|
33 |
-
$thisKey = $hashArr[0];
|
34 |
-
$randomSalt = $hashArr[1];
|
35 |
-
$apiKey = $vbulletin->options['aitmagentovb_apikey'];
|
36 |
-
$realKey = md5( md5($apiKey . $secureSalt) . $randomSalt);
|
37 |
-
if ($realKey == $thisKey)
|
38 |
-
{
|
39 |
-
$sql = '
|
40 |
-
SELECT
|
41 |
-
*,
|
42 |
-
IF(`validthru` < NOW(), 1, 0) AS is_expired
|
43 |
-
FROM `'.TABLE_PREFIX.'aitmagentovb_hash`
|
44 |
-
WHERE `hash` = "'.$hash.'"
|
45 |
-
';
|
46 |
-
// it's safe enough for non-escape usage of $hash here
|
47 |
-
$hashRow = $vbulletin->db->query_first($sql);
|
48 |
-
if ($hashRow AND $hashRow['hashid'])
|
49 |
-
{
|
50 |
-
$vbulletin->db->query_write('
|
51 |
-
DELETE FROM `'.TABLE_PREFIX.'aitmagentovb_hash`
|
52 |
-
WHERE `hashid`='.$hashRow['hashid']
|
53 |
-
);
|
54 |
-
|
55 |
-
if (!$hashRow['is_expired'] AND 'mage' == $hashRow['created_by'])
|
56 |
-
{
|
57 |
-
return true;
|
58 |
-
}
|
59 |
-
}
|
60 |
-
}
|
61 |
-
}
|
62 |
-
|
63 |
-
return false;
|
64 |
-
}
|
65 |
-
|
66 |
-
static public function outputJsonResult($result, $die = false)
|
67 |
-
{
|
68 |
-
$s = Ait_Zend_Json::encode($result);
|
69 |
-
|
70 |
-
header('Content-Type: text/json');
|
71 |
-
header('Content-Length: ' . strlen($s));
|
72 |
-
echo $s;
|
73 |
-
if ($die)
|
74 |
-
{
|
75 |
-
exit;
|
76 |
-
}
|
77 |
-
}
|
78 |
-
|
79 |
-
static public function outputBlankGif()
|
80 |
-
{
|
81 |
-
// transparent GIF 1x1 pixel // real binary data is needed for login/logout images
|
82 |
-
$sBlankGifBase64 = 'R0lGODlhAQABAID/AP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
|
83 |
-
$sBlankGif = base64_decode($sBlankGifBase64);
|
84 |
-
|
85 |
-
header('Content-Type: image/gif');
|
86 |
-
header('Content-Length: ' . strlen($sBlankGif));
|
87 |
-
echo $sBlankGif;
|
88 |
-
exit;
|
89 |
-
}
|
90 |
-
|
91 |
-
/**
|
92 |
-
* Generate a password salt
|
93 |
-
*
|
94 |
-
* @return string
|
95 |
-
*/
|
96 |
-
static public function generateVbPasswordSalt()
|
97 |
-
{
|
98 |
-
$hashSalt = '';
|
99 |
-
for ($i = 0; $i < 3; $i++)
|
100 |
-
{
|
101 |
-
$hashSalt .= chr(rand(0x41, 0x5A)); // A..Z
|
102 |
-
}
|
103 |
-
|
104 |
-
return $hashSalt;
|
105 |
-
}
|
106 |
-
|
107 |
-
static public function generateApiHash($urlencode, $secureSalt)
|
108 |
-
{
|
109 |
-
global $vbulletin;
|
110 |
-
|
111 |
-
$apiKey = $vbulletin->options['aitmagentovb_apikey'];
|
112 |
-
$randomSalt = self::generateVbPasswordSalt();
|
113 |
-
|
114 |
-
$hash = md5( md5($apiKey.$secureSalt) . $randomSalt ) . ':' . $randomSalt;
|
115 |
-
|
116 |
-
// store hash and its lifetime to vbulletin database
|
117 |
-
self::storeHashLifetime($hash);
|
118 |
-
|
119 |
-
if ($urlencode)
|
120 |
-
{
|
121 |
-
$hash = rawurlencode($hash);
|
122 |
-
}
|
123 |
-
|
124 |
-
return $hash;
|
125 |
-
}
|
126 |
-
|
127 |
-
static public function mergeRequestVars($aVars, $urlencode = true, $varskey = '')
|
128 |
-
{
|
129 |
-
if (!$aVars) return '';
|
130 |
-
|
131 |
-
$sReq = '';
|
132 |
-
foreach ($aVars as $key => $val)
|
133 |
-
{
|
134 |
-
if (is_array($val))
|
135 |
-
{
|
136 |
-
$key = $varskey ? $varskey.'['.$key.']' : $key;
|
137 |
-
$sReq .= '&'.self::mergeRequestVars($val, $urlencode, $key);
|
138 |
-
}
|
139 |
-
else
|
140 |
-
{
|
141 |
-
$val = ($urlencode ? rawurlencode($val) : $val);
|
142 |
-
if ($varskey)
|
143 |
-
{
|
144 |
-
$sReq .= '&'.$varskey.'['.$key.']='.$val;
|
145 |
-
}
|
146 |
-
else
|
147 |
-
{
|
148 |
-
$sReq .= '&'.$key.'='.$val;
|
149 |
-
}
|
150 |
-
}
|
151 |
-
}
|
152 |
-
$sReq = substr($sReq, 1);
|
153 |
-
return $sReq;
|
154 |
-
}
|
155 |
-
|
156 |
-
static public function getProxyUrl($aVars, $mageLink, $secureSalt)
|
157 |
-
{
|
158 |
-
global $vbulletin;
|
159 |
-
|
160 |
-
$_allowed_proxy_actions = array(
|
161 |
-
'login',
|
162 |
-
'logout',
|
163 |
-
'unlink', /** @since 0.3.0 */
|
164 |
-
);
|
165 |
-
|
166 |
-
if (!isset($aVars['do']) OR !in_array($aVars['do'], $_allowed_proxy_actions))
|
167 |
-
{
|
168 |
-
return '';
|
169 |
-
}
|
170 |
-
|
171 |
-
if (is_null($mageLink))
|
172 |
-
{
|
173 |
-
$mageLink = $vbulletin->options['aitmagentovb_url'];
|
174 |
-
}
|
175 |
-
$mageLink = rtrim($mageLink, '/') . '/';
|
176 |
-
|
177 |
-
$url = $mageLink . 'aitvbulletin/proxy/' . $aVars['do'] . '/?';
|
178 |
-
unset($aVars['do']);
|
179 |
-
|
180 |
-
$aVars['h'] = self::generateApiHash(false, $secureSalt);
|
181 |
-
|
182 |
-
$url .= self::mergeRequestVars($aVars, true);
|
183 |
-
|
184 |
-
return $url;
|
185 |
-
}
|
186 |
-
|
187 |
-
static public function storeHashLifetime($hash)
|
188 |
-
{
|
189 |
-
global $vbulletin;
|
190 |
-
|
191 |
-
if (!$hash) return false;
|
192 |
-
|
193 |
-
$validThru = TIMENOW + self::APIKEY_HASH_LIFETIME;
|
194 |
-
|
195 |
-
$vbulletin->db->query_write('
|
196 |
-
INSERT INTO `'.TABLE_PREFIX.'aitmagentovb_hash`
|
197 |
-
(`hash`, `validthru`, `created_by`)
|
198 |
-
VALUES
|
199 |
-
("'.$vbulletin->db->escape_string($hash).'", "'.date('Y-m-d H:i:s', $validThru).'", "vbul")
|
200 |
-
');
|
201 |
-
}
|
202 |
-
|
203 |
-
static public function cleanHashes()
|
204 |
-
{
|
205 |
-
global $vbulletin;
|
206 |
-
|
207 |
-
$vbulletin->db->query_write('
|
208 |
-
DELETE FROM `'.TABLE_PREFIX.'aitmagentovb_hash`
|
209 |
-
WHERE LENGTH(`hash`) != 36
|
210 |
-
OR `validthru` < NOW()
|
211 |
-
OR `created_by` NOT IN ("mage", "vbul")
|
212 |
-
');
|
213 |
-
}
|
214 |
-
|
215 |
-
static public function curlWrite($method, $url, $http_ver = '1.1', $headers = array(), $body = '')
|
216 |
-
{
|
217 |
-
$ch = curl_init();
|
218 |
-
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
|
219 |
-
curl_setopt($ch, CURLOPT_REFERER, 'http://' . $_SERVER['HTTP_HOST']);
|
220 |
-
curl_setopt($ch, CURLOPT_TIMEOUT, self::CURL_TIMEOUT_SEC);
|
221 |
-
curl_setopt($ch, CURLOPT_URL, $url);
|
222 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
223 |
-
if ($method == 'POST')
|
224 |
-
{
|
225 |
-
curl_setopt($ch, CURLOPT_POST, true);
|
226 |
-
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
227 |
-
}
|
228 |
-
elseif ($method == 'GET')
|
229 |
-
{
|
230 |
-
curl_setopt($ch, CURLOPT_HTTPGET, true);
|
231 |
-
}
|
232 |
-
|
233 |
-
if ( is_array($headers) )
|
234 |
-
{
|
235 |
-
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
236 |
-
}
|
237 |
-
|
238 |
-
curl_setopt($ch, CURLOPT_HEADER, true);
|
239 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
240 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
241 |
-
|
242 |
-
$result = curl_exec($ch);
|
243 |
-
|
244 |
-
if (!$result) return array();
|
245 |
-
|
246 |
-
// Remove 100 and 101 responses headers
|
247 |
-
if (Ait_Zend_Http_Response::extractCode($result) == 100 ||
|
248 |
-
Ait_Zend_Http_Response::extractCode($result) == 101) {
|
249 |
-
$result = preg_split('/^\r?$/m', $result, 2);
|
250 |
-
$result = trim($result[1]);
|
251 |
-
}
|
252 |
-
|
253 |
-
$oResponse = Ait_Zend_Http_Response::fromString($result);
|
254 |
-
$sResponce = trim($oResponse->getRawBody());
|
255 |
-
$aResponce = Ait_Zend_Json::decode($sResponce);
|
256 |
-
|
257 |
-
return $aResponce;
|
258 |
-
}
|
259 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
-
class Ait_Zend_Exception extends Exception {}
|
4 |
-
class Ait_Zend_Http_Exception extends Ait_Zend_Exception {}
|
5 |
-
class Ait_Zend_Json_Exception extends Ait_Zend_Exception {}
|
6 |
-
|
7 |
-
/**
|
8 |
-
* Zend Framework
|
9 |
-
*
|
10 |
-
* LICENSE
|
11 |
-
*
|
12 |
-
* This source file is subject to the new BSD license that is bundled
|
13 |
-
* with this package in the file LICENSE.txt.
|
14 |
-
* It is also available through the world-wide-web at this URL:
|
15 |
-
* http://framework.zend.com/license/new-bsd
|
16 |
-
* If you did not receive a copy of the license and are unable to
|
17 |
-
* obtain it through the world-wide-web, please send an email
|
18 |
-
* to license@zend.com so we can send you a copy immediately.
|
19 |
-
*
|
20 |
-
* @category Zend
|
21 |
-
* @package Zend_Json
|
22 |
-
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
23 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
24 |
-
*/
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Class for encoding to and decoding from JSON.
|
28 |
-
*
|
29 |
-
* @category Zend
|
30 |
-
* @package Zend_Json
|
31 |
-
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
32 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
33 |
-
*/
|
34 |
-
class Ait_Zend_Json
|
35 |
-
{
|
36 |
-
/**
|
37 |
-
* How objects should be encoded -- arrays or as StdClass. TYPE_ARRAY is 1
|
38 |
-
* so that it is a boolean true value, allowing it to be used with
|
39 |
-
* ext/json's functions.
|
40 |
-
*/
|
41 |
-
const TYPE_ARRAY = 1;
|
42 |
-
const TYPE_OBJECT = 0;
|
43 |
-
|
44 |
-
/**
|
45 |
-
* To check the allowed nesting depth of the XML tree during xml2json conversion.
|
46 |
-
*
|
47 |
-
* @var int
|
48 |
-
*/
|
49 |
-
public static $maxRecursionDepthAllowed=25;
|
50 |
-
|
51 |
-
/**
|
52 |
-
* @var bool
|
53 |
-
*/
|
54 |
-
public static $useBuiltinEncoderDecoder = false;
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Decodes the given $encodedValue string which is
|
58 |
-
* encoded in the JSON format
|
59 |
-
*
|
60 |
-
* Uses ext/json's json_decode if available.
|
61 |
-
*
|
62 |
-
* @param string $encodedValue Encoded in JSON format
|
63 |
-
* @param int $objectDecodeType Optional; flag indicating how to decode
|
64 |
-
* objects. See {@link Zend_Json_Decoder::decode()} for details.
|
65 |
-
* @return mixed
|
66 |
-
*/
|
67 |
-
public static function decode($encodedValue, $objectDecodeType = Ait_Zend_Json::TYPE_ARRAY)
|
68 |
-
{
|
69 |
-
if (function_exists('json_decode') && self::$useBuiltinEncoderDecoder !== true) {
|
70 |
-
return json_decode($encodedValue, $objectDecodeType);
|
71 |
-
}
|
72 |
-
|
73 |
-
return Ait_Zend_Json_Decoder::decode($encodedValue, $objectDecodeType);
|
74 |
-
}
|
75 |
-
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Encode the mixed $valueToEncode into the JSON format
|
79 |
-
*
|
80 |
-
* Encodes using ext/json's json_encode() if available.
|
81 |
-
*
|
82 |
-
* NOTE: Object should not contain cycles; the JSON format
|
83 |
-
* does not allow object reference.
|
84 |
-
*
|
85 |
-
* NOTE: Only public variables will be encoded
|
86 |
-
*
|
87 |
-
* @param mixed $valueToEncode
|
88 |
-
* @param boolean $cycleCheck Optional; whether or not to check for object recursion; off by default
|
89 |
-
* @param array $options Additional options used during encoding
|
90 |
-
* @return string JSON encoded object
|
91 |
-
*/
|
92 |
-
public static function encode($valueToEncode, $cycleCheck = false, $options = array())
|
93 |
-
{
|
94 |
-
if (is_object($valueToEncode) && method_exists($valueToEncode, 'toJson')) {
|
95 |
-
return $valueToEncode->toJson();
|
96 |
-
}
|
97 |
-
|
98 |
-
if (function_exists('json_encode') && self::$useBuiltinEncoderDecoder !== true) {
|
99 |
-
return json_encode($valueToEncode);
|
100 |
-
}
|
101 |
-
|
102 |
-
return Ait_Zend_Json_Encoder::encode($valueToEncode, $cycleCheck, $options);
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* fromXml - Converts XML to JSON
|
107 |
-
*
|
108 |
-
* Converts a XML formatted string into a JSON formatted string.
|
109 |
-
* The value returned will be a string in JSON format.
|
110 |
-
*
|
111 |
-
* The caller of this function needs to provide only the first parameter,
|
112 |
-
* which is an XML formatted String. The second parameter is optional, which
|
113 |
-
* lets the user to select if the XML attributes in the input XML string
|
114 |
-
* should be included or ignored in xml2json conversion.
|
115 |
-
*
|
116 |
-
* This function converts the XML formatted string into a PHP array by
|
117 |
-
* calling a recursive (protected static) function in this class. Then, it
|
118 |
-
* converts that PHP array into JSON by calling the "encode" static funcion.
|
119 |
-
*
|
120 |
-
* Throws a Zend_Json_Exception if the input not a XML formatted string.
|
121 |
-
*
|
122 |
-
* @static
|
123 |
-
* @access public
|
124 |
-
* @param string $xmlStringContents XML String to be converted
|
125 |
-
* @param boolean $ignoreXmlAttributes Include or exclude XML attributes in
|
126 |
-
* the xml2json conversion process.
|
127 |
-
* @return mixed - JSON formatted string on success
|
128 |
-
* @throws Ait_Zend_Json_Exception
|
129 |
-
*/
|
130 |
-
public static function fromXml ($xmlStringContents, $ignoreXmlAttributes=true) {
|
131 |
-
// Load the XML formatted string into a Simple XML Element object.
|
132 |
-
$simpleXmlElementObject = simplexml_load_string($xmlStringContents);
|
133 |
-
|
134 |
-
// If it is not a valid XML content, throw an exception.
|
135 |
-
if ($simpleXmlElementObject == null) {
|
136 |
-
throw new Ait_Zend_Json_Exception('Function fromXml was called with an invalid XML formatted string.');
|
137 |
-
} // End of if ($simpleXmlElementObject == null)
|
138 |
-
|
139 |
-
$resultArray = null;
|
140 |
-
|
141 |
-
// Call the recursive function to convert the XML into a PHP array.
|
142 |
-
$resultArray = self::_processXml($simpleXmlElementObject, $ignoreXmlAttributes);
|
143 |
-
|
144 |
-
// Convert the PHP array to JSON using Zend_Json encode method.
|
145 |
-
// It is just that simple.
|
146 |
-
$jsonStringOutput = self::encode($resultArray);
|
147 |
-
return($jsonStringOutput);
|
148 |
-
} // End of function fromXml.
|
149 |
-
|
150 |
-
/**
|
151 |
-
* _processXml - Contains the logic for xml2json
|
152 |
-
*
|
153 |
-
* The logic in this function is a recursive one.
|
154 |
-
*
|
155 |
-
* The main caller of this function (i.e. fromXml) needs to provide
|
156 |
-
* only the first two parameters i.e. the SimpleXMLElement object and
|
157 |
-
* the flag for ignoring or not ignoring XML attributes. The third parameter
|
158 |
-
* will be used internally within this function during the recursive calls.
|
159 |
-
*
|
160 |
-
* This function converts the SimpleXMLElement object into a PHP array by
|
161 |
-
* calling a recursive (protected static) function in this class. Once all
|
162 |
-
* the XML elements are stored in the PHP array, it is returned to the caller.
|
163 |
-
*
|
164 |
-
* Throws a Zend_Json_Exception if the XML tree is deeper than the allowed limit.
|
165 |
-
*
|
166 |
-
* @static
|
167 |
-
* @access protected
|
168 |
-
* @param SimpleXMLElement $simpleXmlElementObject XML element to be converted
|
169 |
-
* @param boolean $ignoreXmlAttributes Include or exclude XML attributes in
|
170 |
-
* the xml2json conversion process.
|
171 |
-
* @param int $recursionDepth Current recursion depth of this function
|
172 |
-
* @return mixed - On success, a PHP associative array of traversed XML elements
|
173 |
-
* @throws Ait_Zend_Json_Exception
|
174 |
-
*/
|
175 |
-
protected static function _processXml ($simpleXmlElementObject, $ignoreXmlAttributes, $recursionDepth=0) {
|
176 |
-
// Keep an eye on how deeply we are involved in recursion.
|
177 |
-
if ($recursionDepth > self::$maxRecursionDepthAllowed) {
|
178 |
-
// XML tree is too deep. Exit now by throwing an exception.
|
179 |
-
throw new Ait_Zend_Json_Exception(
|
180 |
-
"Function _processXml exceeded the allowed recursion depth of " .
|
181 |
-
self::$maxRecursionDepthAllowed);
|
182 |
-
} // End of if ($recursionDepth > self::$maxRecursionDepthAllowed)
|
183 |
-
|
184 |
-
if ($recursionDepth == 0) {
|
185 |
-
// Store the original SimpleXmlElementObject sent by the caller.
|
186 |
-
// We will need it at the very end when we return from here for good.
|
187 |
-
$callerProvidedSimpleXmlElementObject = $simpleXmlElementObject;
|
188 |
-
} // End of if ($recursionDepth == 0)
|
189 |
-
|
190 |
-
if ($simpleXmlElementObject instanceof SimpleXMLElement) {
|
191 |
-
// Get a copy of the simpleXmlElementObject
|
192 |
-
$copyOfSimpleXmlElementObject = $simpleXmlElementObject;
|
193 |
-
// Get the object variables in the SimpleXmlElement object for us to iterate.
|
194 |
-
$simpleXmlElementObject = get_object_vars($simpleXmlElementObject);
|
195 |
-
} // End of if (get_class($simpleXmlElementObject) == "SimpleXMLElement")
|
196 |
-
|
197 |
-
// It needs to be an array of object variables.
|
198 |
-
if (is_array($simpleXmlElementObject)) {
|
199 |
-
// Initialize a result array.
|
200 |
-
$resultArray = array();
|
201 |
-
// Is the input array size 0? Then, we reached the rare CDATA text if any.
|
202 |
-
if (count($simpleXmlElementObject) <= 0) {
|
203 |
-
// Let us return the lonely CDATA. It could even be
|
204 |
-
// an empty element or just filled with whitespaces.
|
205 |
-
return (trim(strval($copyOfSimpleXmlElementObject)));
|
206 |
-
} // End of if (count($simpleXmlElementObject) <= 0)
|
207 |
-
|
208 |
-
// Let us walk through the child elements now.
|
209 |
-
foreach($simpleXmlElementObject as $key=>$value) {
|
210 |
-
// Check if we need to ignore the XML attributes.
|
211 |
-
// If yes, you can skip processing the XML attributes.
|
212 |
-
// Otherwise, add the XML attributes to the result array.
|
213 |
-
if(($ignoreXmlAttributes == true) && (is_string($key)) && ($key == "@attributes")) {
|
214 |
-
continue;
|
215 |
-
} // End of if(($ignoreXmlAttributes == true) && ($key == "@attributes"))
|
216 |
-
|
217 |
-
// Let us recursively process the current XML element we just visited.
|
218 |
-
// Increase the recursion depth by one.
|
219 |
-
$recursionDepth++;
|
220 |
-
$resultArray[$key] = self::_processXml ($value, $ignoreXmlAttributes, $recursionDepth);
|
221 |
-
|
222 |
-
// Decrease the recursion depth by one.
|
223 |
-
$recursionDepth--;
|
224 |
-
} // End of foreach($simpleXmlElementObject as $key=>$value) {
|
225 |
-
|
226 |
-
if ($recursionDepth == 0) {
|
227 |
-
// That is it. We are heading to the exit now.
|
228 |
-
// Set the XML root element name as the root [top-level] key of
|
229 |
-
// the associative array that we are going to return to the original
|
230 |
-
// caller of this recursive function.
|
231 |
-
$tempArray = $resultArray;
|
232 |
-
$resultArray = array();
|
233 |
-
$resultArray[$callerProvidedSimpleXmlElementObject->getName()] = $tempArray;
|
234 |
-
} // End of if ($recursionDepth == 0)
|
235 |
-
|
236 |
-
return($resultArray);
|
237 |
-
} else {
|
238 |
-
// We are now looking at either the XML attribute text or
|
239 |
-
// the text between the XML tags.
|
240 |
-
return (trim(strval($simpleXmlElementObject)));
|
241 |
-
} // End of if (is_array($simpleXmlElementObject))
|
242 |
-
} // End of function _processXml.
|
243 |
-
}
|
244 |
-
|
245 |
-
/**
|
246 |
-
* Encode PHP constructs to JSON
|
247 |
-
*
|
248 |
-
* @category Zend
|
249 |
-
* @package Zend_Json
|
250 |
-
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
251 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
252 |
-
*/
|
253 |
-
class Ait_Zend_Json_Encoder
|
254 |
-
{
|
255 |
-
/**
|
256 |
-
* Whether or not to check for possible cycling
|
257 |
-
*
|
258 |
-
* @var boolean
|
259 |
-
*/
|
260 |
-
protected $_cycleCheck;
|
261 |
-
|
262 |
-
/**
|
263 |
-
* Additional options used during encoding
|
264 |
-
*
|
265 |
-
* @var array
|
266 |
-
*/
|
267 |
-
protected $_options = array();
|
268 |
-
|
269 |
-
/**
|
270 |
-
* Array of visited objects; used to prevent cycling.
|
271 |
-
*
|
272 |
-
* @var array
|
273 |
-
*/
|
274 |
-
protected $_visited = array();
|
275 |
-
|
276 |
-
/**
|
277 |
-
* Constructor
|
278 |
-
*
|
279 |
-
* @param boolean $cycleCheck Whether or not to check for recursion when encoding
|
280 |
-
* @param array $options Additional options used during encoding
|
281 |
-
* @return void
|
282 |
-
*/
|
283 |
-
protected function __construct($cycleCheck = false, $options = array())
|
284 |
-
{
|
285 |
-
$this->_cycleCheck = $cycleCheck;
|
286 |
-
$this->_options = $options;
|
287 |
-
}
|
288 |
-
|
289 |
-
/**
|
290 |
-
* Use the JSON encoding scheme for the value specified
|
291 |
-
*
|
292 |
-
* @param mixed $value The value to be encoded
|
293 |
-
* @param boolean $cycleCheck Whether or not to check for possible object recursion when encoding
|
294 |
-
* @param array $options Additional options used during encoding
|
295 |
-
* @return string The encoded value
|
296 |
-
*/
|
297 |
-
public static function encode($value, $cycleCheck = false, $options = array())
|
298 |
-
{
|
299 |
-
$encoder = new self(($cycleCheck) ? true : false, $options);
|
300 |
-
|
301 |
-
return $encoder->_encodeValue($value);
|
302 |
-
}
|
303 |
-
|
304 |
-
/**
|
305 |
-
* Recursive driver which determines the type of value to be encoded
|
306 |
-
* and then dispatches to the appropriate method. $values are either
|
307 |
-
* - objects (returns from {@link _encodeObject()})
|
308 |
-
* - arrays (returns from {@link _encodeArray()})
|
309 |
-
* - basic datums (e.g. numbers or strings) (returns from {@link _encodeDatum()})
|
310 |
-
*
|
311 |
-
* @param $value mixed The value to be encoded
|
312 |
-
* @return string Encoded value
|
313 |
-
*/
|
314 |
-
protected function _encodeValue(&$value)
|
315 |
-
{
|
316 |
-
if (is_object($value)) {
|
317 |
-
return $this->_encodeObject($value);
|
318 |
-
} else if (is_array($value)) {
|
319 |
-
return $this->_encodeArray($value);
|
320 |
-
}
|
321 |
-
|
322 |
-
return $this->_encodeDatum($value);
|
323 |
-
}
|
324 |
-
|
325 |
-
/**
|
326 |
-
* Encode an object to JSON by encoding each of the public properties
|
327 |
-
*
|
328 |
-
* A special property is added to the JSON object called '__className'
|
329 |
-
* that contains the name of the class of $value. This is used to decode
|
330 |
-
* the object on the client into a specific class.
|
331 |
-
*
|
332 |
-
* @param $value object
|
333 |
-
* @return string
|
334 |
-
* @throws Ait_Zend_Json_Exception If recursive checks are enabled and the object has been serialized previously
|
335 |
-
*/
|
336 |
-
protected function _encodeObject(&$value)
|
337 |
-
{
|
338 |
-
if ($this->_cycleCheck) {
|
339 |
-
if ($this->_wasVisited($value)) {
|
340 |
-
|
341 |
-
if (isset($this->_options['silenceCyclicalExceptions'])
|
342 |
-
&& $this->_options['silenceCyclicalExceptions']===true) {
|
343 |
-
|
344 |
-
return '"* RECURSION (' . get_class($value) . ') *"';
|
345 |
-
|
346 |
-
} else {
|
347 |
-
throw new Ait_Zend_Json_Exception(
|
348 |
-
'Cycles not supported in JSON encoding, cycle introduced by '
|
349 |
-
. 'class "' . get_class($value) . '"'
|
350 |
-
);
|
351 |
-
}
|
352 |
-
}
|
353 |
-
|
354 |
-
$this->_visited[] = $value;
|
355 |
-
}
|
356 |
-
|
357 |
-
$props = '';
|
358 |
-
|
359 |
-
if ($value instanceof Iterator) {
|
360 |
-
$propCollection = $value;
|
361 |
-
} else {
|
362 |
-
$propCollection = get_object_vars($value);
|
363 |
-
}
|
364 |
-
|
365 |
-
foreach ($propCollection as $name => $propValue) {
|
366 |
-
if (isset($propValue)) {
|
367 |
-
$props .= ','
|
368 |
-
. $this->_encodeValue($name)
|
369 |
-
. ':'
|
370 |
-
. $this->_encodeValue($propValue);
|
371 |
-
}
|
372 |
-
}
|
373 |
-
|
374 |
-
return '{"__className":"' . get_class($value) . '"'
|
375 |
-
. $props . '}';
|
376 |
-
}
|
377 |
-
|
378 |
-
/**
|
379 |
-
* Determine if an object has been serialized already
|
380 |
-
*
|
381 |
-
* @param mixed $value
|
382 |
-
* @return boolean
|
383 |
-
*/
|
384 |
-
protected function _wasVisited(&$value)
|
385 |
-
{
|
386 |
-
if (in_array($value, $this->_visited, true)) {
|
387 |
-
return true;
|
388 |
-
}
|
389 |
-
|
390 |
-
return false;
|
391 |
-
}
|
392 |
-
|
393 |
-
/**
|
394 |
-
* JSON encode an array value
|
395 |
-
*
|
396 |
-
* Recursively encodes each value of an array and returns a JSON encoded
|
397 |
-
* array string.
|
398 |
-
*
|
399 |
-
* Arrays are defined as integer-indexed arrays starting at index 0, where
|
400 |
-
* the last index is (count($array) -1); any deviation from that is
|
401 |
-
* considered an associative array, and will be encoded as such.
|
402 |
-
*
|
403 |
-
* @param $array array
|
404 |
-
* @return string
|
405 |
-
*/
|
406 |
-
protected function _encodeArray(&$array)
|
407 |
-
{
|
408 |
-
$tmpArray = array();
|
409 |
-
|
410 |
-
// Check for associative array
|
411 |
-
if (!empty($array) && (array_keys($array) !== range(0, count($array) - 1))) {
|
412 |
-
// Associative array
|
413 |
-
$result = '{';
|
414 |
-
foreach ($array as $key => $value) {
|
415 |
-
$key = (string) $key;
|
416 |
-
$tmpArray[] = $this->_encodeString($key)
|
417 |
-
. ':'
|
418 |
-
. $this->_encodeValue($value);
|
419 |
-
}
|
420 |
-
$result .= implode(',', $tmpArray);
|
421 |
-
$result .= '}';
|
422 |
-
} else {
|
423 |
-
// Indexed array
|
424 |
-
$result = '[';
|
425 |
-
$length = count($array);
|
426 |
-
for ($i = 0; $i < $length; $i++) {
|
427 |
-
$tmpArray[] = $this->_encodeValue($array[$i]);
|
428 |
-
}
|
429 |
-
$result .= implode(',', $tmpArray);
|
430 |
-
$result .= ']';
|
431 |
-
}
|
432 |
-
|
433 |
-
return $result;
|
434 |
-
}
|
435 |
-
|
436 |
-
/**
|
437 |
-
* JSON encode a basic data type (string, number, boolean, null)
|
438 |
-
*
|
439 |
-
* If value type is not a string, number, boolean, or null, the string
|
440 |
-
* 'null' is returned.
|
441 |
-
*
|
442 |
-
* @param $value mixed
|
443 |
-
* @return string
|
444 |
-
*/
|
445 |
-
protected function _encodeDatum(&$value)
|
446 |
-
{
|
447 |
-
$result = 'null';
|
448 |
-
|
449 |
-
if (is_int($value) || is_float($value)) {
|
450 |
-
$result = (string) $value;
|
451 |
-
} elseif (is_string($value)) {
|
452 |
-
$result = $this->_encodeString($value);
|
453 |
-
} elseif (is_bool($value)) {
|
454 |
-
$result = $value ? 'true' : 'false';
|
455 |
-
}
|
456 |
-
|
457 |
-
return $result;
|
458 |
-
}
|
459 |
-
|
460 |
-
/**
|
461 |
-
* JSON encode a string value by escaping characters as necessary
|
462 |
-
*
|
463 |
-
* @param $value string
|
464 |
-
* @return string
|
465 |
-
*/
|
466 |
-
protected function _encodeString(&$string)
|
467 |
-
{
|
468 |
-
// Escape these characters with a backslash:
|
469 |
-
// " \ / \n \r \t \b \f
|
470 |
-
$search = array('\\', "\n", "\t", "\r", "\b", "\f", '"');
|
471 |
-
$replace = array('\\\\', '\\n', '\\t', '\\r', '\\b', '\\f', '\"');
|
472 |
-
$string = str_replace($search, $replace, $string);
|
473 |
-
|
474 |
-
// Escape certain ASCII characters:
|
475 |
-
// 0x08 => \b
|
476 |
-
// 0x0c => \f
|
477 |
-
$string = str_replace(array(chr(0x08), chr(0x0C)), array('\b', '\f'), $string);
|
478 |
-
|
479 |
-
return '"' . $string . '"';
|
480 |
-
}
|
481 |
-
|
482 |
-
/**
|
483 |
-
* Encode the constants associated with the ReflectionClass
|
484 |
-
* parameter. The encoding format is based on the class2 format
|
485 |
-
*
|
486 |
-
* @param $cls ReflectionClass
|
487 |
-
* @return string Encoded constant block in class2 format
|
488 |
-
*/
|
489 |
-
private static function _encodeConstants(ReflectionClass $cls)
|
490 |
-
{
|
491 |
-
$result = "constants : {";
|
492 |
-
$constants = $cls->getConstants();
|
493 |
-
|
494 |
-
$tmpArray = array();
|
495 |
-
if (!empty($constants)) {
|
496 |
-
foreach ($constants as $key => $value) {
|
497 |
-
$tmpArray[] = "$key: " . self::encode($value);
|
498 |
-
}
|
499 |
-
|
500 |
-
$result .= implode(', ', $tmpArray);
|
501 |
-
}
|
502 |
-
|
503 |
-
return $result . "}";
|
504 |
-
}
|
505 |
-
|
506 |
-
/**
|
507 |
-
* Encode the public methods of the ReflectionClass in the
|
508 |
-
* class2 format
|
509 |
-
*
|
510 |
-
* @param $cls ReflectionClass
|
511 |
-
* @return string Encoded method fragment
|
512 |
-
*
|
513 |
-
*/
|
514 |
-
private static function _encodeMethods(ReflectionClass $cls)
|
515 |
-
{
|
516 |
-
$methods = $cls->getMethods();
|
517 |
-
$result = 'methods:{';
|
518 |
-
|
519 |
-
$started = false;
|
520 |
-
foreach ($methods as $method) {
|
521 |
-
if (! $method->isPublic() || !$method->isUserDefined()) {
|
522 |
-
continue;
|
523 |
-
}
|
524 |
-
|
525 |
-
if ($started) {
|
526 |
-
$result .= ',';
|
527 |
-
}
|
528 |
-
$started = true;
|
529 |
-
|
530 |
-
$result .= '' . $method->getName(). ':function(';
|
531 |
-
|
532 |
-
if ('__construct' != $method->getName()) {
|
533 |
-
$parameters = $method->getParameters();
|
534 |
-
$paramCount = count($parameters);
|
535 |
-
$argsStarted = false;
|
536 |
-
|
537 |
-
$argNames = "var argNames=[";
|
538 |
-
foreach ($parameters as $param) {
|
539 |
-
if ($argsStarted) {
|
540 |
-
$result .= ',';
|
541 |
-
}
|
542 |
-
|
543 |
-
$result .= $param->getName();
|
544 |
-
|
545 |
-
if ($argsStarted) {
|
546 |
-
$argNames .= ',';
|
547 |
-
}
|
548 |
-
|
549 |
-
$argNames .= '"' . $param->getName() . '"';
|
550 |
-
|
551 |
-
$argsStarted = true;
|
552 |
-
}
|
553 |
-
$argNames .= "];";
|
554 |
-
|
555 |
-
$result .= "){"
|
556 |
-
. $argNames
|
557 |
-
. 'var result = ZAjaxEngine.invokeRemoteMethod('
|
558 |
-
. "this, '" . $method->getName()
|
559 |
-
. "',argNames,arguments);"
|
560 |
-
. 'return(result);}';
|
561 |
-
} else {
|
562 |
-
$result .= "){}";
|
563 |
-
}
|
564 |
-
}
|
565 |
-
|
566 |
-
return $result . "}";
|
567 |
-
}
|
568 |
-
|
569 |
-
/**
|
570 |
-
* Encode the public properties of the ReflectionClass in the class2
|
571 |
-
* format.
|
572 |
-
*
|
573 |
-
* @param $cls ReflectionClass
|
574 |
-
* @return string Encode properties list
|
575 |
-
*
|
576 |
-
*/
|
577 |
-
private static function _encodeVariables(ReflectionClass $cls)
|
578 |
-
{
|
579 |
-
$properties = $cls->getProperties();
|
580 |
-
$propValues = get_class_vars($cls->getName());
|
581 |
-
$result = "variables:{";
|
582 |
-
$cnt = 0;
|
583 |
-
|
584 |
-
$tmpArray = array();
|
585 |
-
foreach ($properties as $prop) {
|
586 |
-
if (! $prop->isPublic()) {
|
587 |
-
continue;
|
588 |
-
}
|
589 |
-
|
590 |
-
$tmpArray[] = $prop->getName()
|
591 |
-
. ':'
|
592 |
-
. self::encode($propValues[$prop->getName()]);
|
593 |
-
}
|
594 |
-
$result .= implode(',', $tmpArray);
|
595 |
-
|
596 |
-
return $result . "}";
|
597 |
-
}
|
598 |
-
|
599 |
-
/**
|
600 |
-
* Encodes the given $className into the class2 model of encoding PHP
|
601 |
-
* classes into JavaScript class2 classes.
|
602 |
-
* NOTE: Currently only public methods and variables are proxied onto
|
603 |
-
* the client machine
|
604 |
-
*
|
605 |
-
* @param $className string The name of the class, the class must be
|
606 |
-
* instantiable using a null constructor
|
607 |
-
* @param $package string Optional package name appended to JavaScript
|
608 |
-
* proxy class name
|
609 |
-
* @return string The class2 (JavaScript) encoding of the class
|
610 |
-
* @throws Ait_Zend_Json_Exception
|
611 |
-
*/
|
612 |
-
public static function encodeClass($className, $package = '')
|
613 |
-
{
|
614 |
-
$cls = new ReflectionClass($className);
|
615 |
-
if (! $cls->isInstantiable()) {
|
616 |
-
throw new Ait_Zend_Json_Exception("$className must be instantiable");
|
617 |
-
}
|
618 |
-
|
619 |
-
return "Class.create('$package$className',{"
|
620 |
-
. self::_encodeConstants($cls) .","
|
621 |
-
. self::_encodeMethods($cls) .","
|
622 |
-
. self::_encodeVariables($cls) .'});';
|
623 |
-
}
|
624 |
-
|
625 |
-
/**
|
626 |
-
* Encode several classes at once
|
627 |
-
*
|
628 |
-
* Returns JSON encoded classes, using {@link encodeClass()}.
|
629 |
-
*
|
630 |
-
* @param array $classNames
|
631 |
-
* @param string $package
|
632 |
-
* @return string
|
633 |
-
*/
|
634 |
-
public static function encodeClasses(array $classNames, $package = '')
|
635 |
-
{
|
636 |
-
$result = '';
|
637 |
-
foreach ($classNames as $className) {
|
638 |
-
$result .= self::encodeClass($className, $package);
|
639 |
-
}
|
640 |
-
|
641 |
-
return $result;
|
642 |
-
}
|
643 |
-
}
|
644 |
-
|
645 |
-
/**
|
646 |
-
* Decode JSON encoded string to PHP variable constructs
|
647 |
-
*
|
648 |
-
* @category Zend
|
649 |
-
* @package Zend_Json
|
650 |
-
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
651 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
652 |
-
*/
|
653 |
-
class Ait_Zend_Json_Decoder
|
654 |
-
{
|
655 |
-
/**
|
656 |
-
* Parse tokens used to decode the JSON object. These are not
|
657 |
-
* for public consumption, they are just used internally to the
|
658 |
-
* class.
|
659 |
-
*/
|
660 |
-
const EOF = 0;
|
661 |
-
const DATUM = 1;
|
662 |
-
const LBRACE = 2;
|
663 |
-
const LBRACKET = 3;
|
664 |
-
const RBRACE = 4;
|
665 |
-
const RBRACKET = 5;
|
666 |
-
const COMMA = 6;
|
667 |
-
const COLON = 7;
|
668 |
-
|
669 |
-
/**
|
670 |
-
* Use to maintain a "pointer" to the source being decoded
|
671 |
-
*
|
672 |
-
* @var string
|
673 |
-
*/
|
674 |
-
protected $_source;
|
675 |
-
|
676 |
-
/**
|
677 |
-
* Caches the source length
|
678 |
-
*
|
679 |
-
* @var int
|
680 |
-
*/
|
681 |
-
protected $_sourceLength;
|
682 |
-
|
683 |
-
/**
|
684 |
-
* The offset within the souce being decoded
|
685 |
-
*
|
686 |
-
* @var int
|
687 |
-
*
|
688 |
-
*/
|
689 |
-
protected $_offset;
|
690 |
-
|
691 |
-
/**
|
692 |
-
* The current token being considered in the parser cycle
|
693 |
-
*
|
694 |
-
* @var int
|
695 |
-
*/
|
696 |
-
protected $_token;
|
697 |
-
|
698 |
-
/**
|
699 |
-
* Flag indicating how objects should be decoded
|
700 |
-
*
|
701 |
-
* @var int
|
702 |
-
* @access protected
|
703 |
-
*/
|
704 |
-
protected $_decodeType;
|
705 |
-
|
706 |
-
/**
|
707 |
-
* Constructor
|
708 |
-
*
|
709 |
-
* @param string $source String source to decode
|
710 |
-
* @param int $decodeType How objects should be decoded -- see
|
711 |
-
* {@link Zend_Json::TYPE_ARRAY} and {@link Zend_Json::TYPE_OBJECT} for
|
712 |
-
* valid values
|
713 |
-
* @return void
|
714 |
-
*/
|
715 |
-
protected function __construct($source, $decodeType)
|
716 |
-
{
|
717 |
-
// Set defaults
|
718 |
-
$this->_source = $source;
|
719 |
-
$this->_sourceLength = strlen($source);
|
720 |
-
$this->_token = self::EOF;
|
721 |
-
$this->_offset = 0;
|
722 |
-
|
723 |
-
// Normalize and set $decodeType
|
724 |
-
if (!in_array($decodeType, array(Ait_Zend_Json::TYPE_ARRAY, Ait_Zend_Json::TYPE_OBJECT)))
|
725 |
-
{
|
726 |
-
$decodeType = Ait_Zend_Json::TYPE_ARRAY;
|
727 |
-
}
|
728 |
-
$this->_decodeType = $decodeType;
|
729 |
-
|
730 |
-
// Set pointer at first token
|
731 |
-
$this->_getNextToken();
|
732 |
-
}
|
733 |
-
|
734 |
-
/**
|
735 |
-
* Decode a JSON source string
|
736 |
-
*
|
737 |
-
* Decodes a JSON encoded string. The value returned will be one of the
|
738 |
-
* following:
|
739 |
-
* - integer
|
740 |
-
* - float
|
741 |
-
* - boolean
|
742 |
-
* - null
|
743 |
-
* - StdClass
|
744 |
-
* - array
|
745 |
-
* - array of one or more of the above types
|
746 |
-
*
|
747 |
-
* By default, decoded objects will be returned as associative arrays; to
|
748 |
-
* return a StdClass object instead, pass {@link Zend_Json::TYPE_OBJECT} to
|
749 |
-
* the $objectDecodeType parameter.
|
750 |
-
*
|
751 |
-
* Throws a Zend_Json_Exception if the source string is null.
|
752 |
-
*
|
753 |
-
* @static
|
754 |
-
* @access public
|
755 |
-
* @param string $source String to be decoded
|
756 |
-
* @param int $objectDecodeType How objects should be decoded; should be
|
757 |
-
* either or {@link Zend_Json::TYPE_ARRAY} or
|
758 |
-
* {@link Zend_Json::TYPE_OBJECT}; defaults to TYPE_ARRAY
|
759 |
-
* @return mixed
|
760 |
-
* @throws Ait_Zend_Json_Exception
|
761 |
-
*/
|
762 |
-
public static function decode($source = null, $objectDecodeType = Ait_Zend_Json::TYPE_ARRAY)
|
763 |
-
{
|
764 |
-
if (null === $source) {
|
765 |
-
throw new Ait_Zend_Json_Exception('Must specify JSON encoded source for decoding');
|
766 |
-
} elseif (!is_string($source)) {
|
767 |
-
throw new Ait_Zend_Json_Exception('Can only decode JSON encoded strings');
|
768 |
-
}
|
769 |
-
|
770 |
-
$decoder = new self($source, $objectDecodeType);
|
771 |
-
|
772 |
-
return $decoder->_decodeValue();
|
773 |
-
}
|
774 |
-
|
775 |
-
/**
|
776 |
-
* Recursive driving rountine for supported toplevel tops
|
777 |
-
*
|
778 |
-
* @return mixed
|
779 |
-
*/
|
780 |
-
protected function _decodeValue()
|
781 |
-
{
|
782 |
-
switch ($this->_token) {
|
783 |
-
case self::DATUM:
|
784 |
-
$result = $this->_tokenValue;
|
785 |
-
$this->_getNextToken();
|
786 |
-
return($result);
|
787 |
-
break;
|
788 |
-
case self::LBRACE:
|
789 |
-
return($this->_decodeObject());
|
790 |
-
break;
|
791 |
-
case self::LBRACKET:
|
792 |
-
return($this->_decodeArray());
|
793 |
-
break;
|
794 |
-
default:
|
795 |
-
return null;
|
796 |
-
break;
|
797 |
-
}
|
798 |
-
}
|
799 |
-
|
800 |
-
/**
|
801 |
-
* Decodes an object of the form:
|
802 |
-
* { "attribute: value, "attribute2" : value,...}
|
803 |
-
*
|
804 |
-
* If Zend_Json_Encoder was used to encode the original object then
|
805 |
-
* a special attribute called __className which specifies a class
|
806 |
-
* name that should wrap the data contained within the encoded source.
|
807 |
-
*
|
808 |
-
* Decodes to either an array or StdClass object, based on the value of
|
809 |
-
* {@link $_decodeType}. If invalid $_decodeType present, returns as an
|
810 |
-
* array.
|
811 |
-
*
|
812 |
-
* @return array|StdClass
|
813 |
-
*/
|
814 |
-
protected function _decodeObject()
|
815 |
-
{
|
816 |
-
$members = array();
|
817 |
-
$tok = $this->_getNextToken();
|
818 |
-
|
819 |
-
while ($tok && $tok != self::RBRACE) {
|
820 |
-
if ($tok != self::DATUM || ! is_string($this->_tokenValue)) {
|
821 |
-
throw new Ait_Zend_Json_Exception('Missing key in object encoding: ' . $this->_source);
|
822 |
-
}
|
823 |
-
|
824 |
-
$key = $this->_tokenValue;
|
825 |
-
$tok = $this->_getNextToken();
|
826 |
-
|
827 |
-
if ($tok != self::COLON) {
|
828 |
-
throw new Ait_Zend_Json_Exception('Missing ":" in object encoding: ' . $this->_source);
|
829 |
-
}
|
830 |
-
|
831 |
-
$tok = $this->_getNextToken();
|
832 |
-
$members[$key] = $this->_decodeValue();
|
833 |
-
$tok = $this->_token;
|
834 |
-
|
835 |
-
if ($tok == self::RBRACE) {
|
836 |
-
break;
|
837 |
-
}
|
838 |
-
|
839 |
-
if ($tok != self::COMMA) {
|
840 |
-
throw new Ait_Zend_Json_Exception('Missing "," in object encoding: ' . $this->_source);
|
841 |
-
}
|
842 |
-
|
843 |
-
$tok = $this->_getNextToken();
|
844 |
-
}
|
845 |
-
|
846 |
-
switch ($this->_decodeType) {
|
847 |
-
case Ait_Zend_Json::TYPE_OBJECT:
|
848 |
-
// Create new StdClass and populate with $members
|
849 |
-
$result = new StdClass();
|
850 |
-
foreach ($members as $key => $value) {
|
851 |
-
$result->$key = $value;
|
852 |
-
}
|
853 |
-
break;
|
854 |
-
case Ait_Zend_Json::TYPE_ARRAY:
|
855 |
-
default:
|
856 |
-
$result = $members;
|
857 |
-
break;
|
858 |
-
}
|
859 |
-
|
860 |
-
$this->_getNextToken();
|
861 |
-
return $result;
|
862 |
-
}
|
863 |
-
|
864 |
-
/**
|
865 |
-
* Decodes a JSON array format:
|
866 |
-
* [element, element2,...,elementN]
|
867 |
-
*
|
868 |
-
* @return array
|
869 |
-
*/
|
870 |
-
protected function _decodeArray()
|
871 |
-
{
|
872 |
-
$result = array();
|
873 |
-
$starttok = $tok = $this->_getNextToken(); // Move past the '['
|
874 |
-
$index = 0;
|
875 |
-
|
876 |
-
while ($tok && $tok != self::RBRACKET) {
|
877 |
-
$result[$index++] = $this->_decodeValue();
|
878 |
-
|
879 |
-
$tok = $this->_token;
|
880 |
-
|
881 |
-
if ($tok == self::RBRACKET || !$tok) {
|
882 |
-
break;
|
883 |
-
}
|
884 |
-
|
885 |
-
if ($tok != self::COMMA) {
|
886 |
-
throw new Ait_Zend_Json_Exception('Missing "," in array encoding: ' . $this->_source);
|
887 |
-
}
|
888 |
-
|
889 |
-
$tok = $this->_getNextToken();
|
890 |
-
}
|
891 |
-
|
892 |
-
$this->_getNextToken();
|
893 |
-
return($result);
|
894 |
-
}
|
895 |
-
|
896 |
-
/**
|
897 |
-
* Removes whitepsace characters from the source input
|
898 |
-
*/
|
899 |
-
protected function _eatWhitespace()
|
900 |
-
{
|
901 |
-
if (preg_match(
|
902 |
-
'/([\t\b\f\n\r ])*/s',
|
903 |
-
$this->_source,
|
904 |
-
$matches,
|
905 |
-
PREG_OFFSET_CAPTURE,
|
906 |
-
$this->_offset)
|
907 |
-
&& $matches[0][1] == $this->_offset)
|
908 |
-
{
|
909 |
-
$this->_offset += strlen($matches[0][0]);
|
910 |
-
}
|
911 |
-
}
|
912 |
-
|
913 |
-
/**
|
914 |
-
* Retrieves the next token from the source stream
|
915 |
-
*
|
916 |
-
* @return int Token constant value specified in class definition
|
917 |
-
*/
|
918 |
-
protected function _getNextToken()
|
919 |
-
{
|
920 |
-
$this->_token = self::EOF;
|
921 |
-
$this->_tokenValue = null;
|
922 |
-
$this->_eatWhitespace();
|
923 |
-
|
924 |
-
if ($this->_offset >= $this->_sourceLength) {
|
925 |
-
return(self::EOF);
|
926 |
-
}
|
927 |
-
|
928 |
-
$str = $this->_source;
|
929 |
-
$str_length = $this->_sourceLength;
|
930 |
-
$i = $this->_offset;
|
931 |
-
$start = $i;
|
932 |
-
|
933 |
-
switch ($str{$i}) {
|
934 |
-
case '{':
|
935 |
-
$this->_token = self::LBRACE;
|
936 |
-
break;
|
937 |
-
case '}':
|
938 |
-
$this->_token = self::RBRACE;
|
939 |
-
break;
|
940 |
-
case '[':
|
941 |
-
$this->_token = self::LBRACKET;
|
942 |
-
break;
|
943 |
-
case ']':
|
944 |
-
$this->_token = self::RBRACKET;
|
945 |
-
break;
|
946 |
-
case ',':
|
947 |
-
$this->_token = self::COMMA;
|
948 |
-
break;
|
949 |
-
case ':':
|
950 |
-
$this->_token = self::COLON;
|
951 |
-
break;
|
952 |
-
case '"':
|
953 |
-
$result = '';
|
954 |
-
do {
|
955 |
-
$i++;
|
956 |
-
if ($i >= $str_length) {
|
957 |
-
break;
|
958 |
-
}
|
959 |
-
|
960 |
-
$chr = $str{$i};
|
961 |
-
if ($chr == '\\') {
|
962 |
-
$i++;
|
963 |
-
if ($i >= $str_length) {
|
964 |
-
break;
|
965 |
-
}
|
966 |
-
$chr = $str{$i};
|
967 |
-
switch ($chr) {
|
968 |
-
case '"' :
|
969 |
-
$result .= '"';
|
970 |
-
break;
|
971 |
-
case '\\':
|
972 |
-
$result .= '\\';
|
973 |
-
break;
|
974 |
-
case '/' :
|
975 |
-
$result .= '/';
|
976 |
-
break;
|
977 |
-
case 'b' :
|
978 |
-
$result .= chr(8);
|
979 |
-
break;
|
980 |
-
case 'f' :
|
981 |
-
$result .= chr(12);
|
982 |
-
break;
|
983 |
-
case 'n' :
|
984 |
-
$result .= chr(10);
|
985 |
-
break;
|
986 |
-
case 'r' :
|
987 |
-
$result .= chr(13);
|
988 |
-
break;
|
989 |
-
case 't' :
|
990 |
-
$result .= chr(9);
|
991 |
-
break;
|
992 |
-
case '\'' :
|
993 |
-
$result .= '\'';
|
994 |
-
break;
|
995 |
-
default:
|
996 |
-
throw new Ait_Zend_Json_Exception("Illegal escape "
|
997 |
-
. "sequence '" . $chr . "'");
|
998 |
-
}
|
999 |
-
} elseif ($chr == '"') {
|
1000 |
-
break;
|
1001 |
-
} else {
|
1002 |
-
$result .= $chr;
|
1003 |
-
}
|
1004 |
-
} while ($i < $str_length);
|
1005 |
-
|
1006 |
-
$this->_token = self::DATUM;
|
1007 |
-
//$this->_tokenValue = substr($str, $start + 1, $i - $start - 1);
|
1008 |
-
$this->_tokenValue = $result;
|
1009 |
-
break;
|
1010 |
-
case 't':
|
1011 |
-
if (($i+ 3) < $str_length && substr($str, $start, 4) == "true") {
|
1012 |
-
$this->_token = self::DATUM;
|
1013 |
-
}
|
1014 |
-
$this->_tokenValue = true;
|
1015 |
-
$i += 3;
|
1016 |
-
break;
|
1017 |
-
case 'f':
|
1018 |
-
if (($i+ 4) < $str_length && substr($str, $start, 5) == "false") {
|
1019 |
-
$this->_token = self::DATUM;
|
1020 |
-
}
|
1021 |
-
$this->_tokenValue = false;
|
1022 |
-
$i += 4;
|
1023 |
-
break;
|
1024 |
-
case 'n':
|
1025 |
-
if (($i+ 3) < $str_length && substr($str, $start, 4) == "null") {
|
1026 |
-
$this->_token = self::DATUM;
|
1027 |
-
}
|
1028 |
-
$this->_tokenValue = NULL;
|
1029 |
-
$i += 3;
|
1030 |
-
break;
|
1031 |
-
}
|
1032 |
-
|
1033 |
-
if ($this->_token != self::EOF) {
|
1034 |
-
$this->_offset = $i + 1; // Consume the last token character
|
1035 |
-
return($this->_token);
|
1036 |
-
}
|
1037 |
-
|
1038 |
-
$chr = $str{$i};
|
1039 |
-
if ($chr == '-' || $chr == '.' || ($chr >= '0' && $chr <= '9')) {
|
1040 |
-
if (preg_match('/-?([0-9])*(\.[0-9]*)?((e|E)((-|\+)?)[0-9]+)?/s',
|
1041 |
-
$str, $matches, PREG_OFFSET_CAPTURE, $start) && $matches[0][1] == $start) {
|
1042 |
-
|
1043 |
-
$datum = $matches[0][0];
|
1044 |
-
|
1045 |
-
if (is_numeric($datum)) {
|
1046 |
-
if (preg_match('/^0\d+$/', $datum)) {
|
1047 |
-
throw new Ait_Zend_Json_Exception("Octal notation not supported by JSON (value: $datum)");
|
1048 |
-
} else {
|
1049 |
-
$val = intval($datum);
|
1050 |
-
$fVal = floatval($datum);
|
1051 |
-
$this->_tokenValue = ($val == $fVal ? $val : $fVal);
|
1052 |
-
}
|
1053 |
-
} else {
|
1054 |
-
throw new Ait_Zend_Json_Exception("Illegal number format: $datum");
|
1055 |
-
}
|
1056 |
-
|
1057 |
-
$this->_token = self::DATUM;
|
1058 |
-
$this->_offset = $start + strlen($datum);
|
1059 |
-
}
|
1060 |
-
} else {
|
1061 |
-
throw new Ait_Zend_Json_Exception('Illegal Token');
|
1062 |
-
}
|
1063 |
-
|
1064 |
-
return($this->_token);
|
1065 |
-
}
|
1066 |
-
}
|
1067 |
-
|
1068 |
-
/**
|
1069 |
-
* Zend Framework
|
1070 |
-
*
|
1071 |
-
* LICENSE
|
1072 |
-
*
|
1073 |
-
* This source file is subject to the new BSD license that is bundled
|
1074 |
-
* with this package in the file LICENSE.txt.
|
1075 |
-
* It is also available through the world-wide-web at this URL:
|
1076 |
-
* http://framework.zend.com/license/new-bsd
|
1077 |
-
* If you did not receive a copy of the license and are unable to
|
1078 |
-
* obtain it through the world-wide-web, please send an email
|
1079 |
-
* to license@zend.com so we can send you a copy immediately.
|
1080 |
-
*
|
1081 |
-
* @category Zend
|
1082 |
-
* @package Zend_Http
|
1083 |
-
* @subpackage Response
|
1084 |
-
* @version $Id: Response.php 12519 2008-11-10 18:41:24Z alexander $
|
1085 |
-
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
1086 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
1087 |
-
*/
|
1088 |
-
|
1089 |
-
/**
|
1090 |
-
* Zend_Http_Response represents an HTTP 1.0 / 1.1 response message. It
|
1091 |
-
* includes easy access to all the response's different elemts, as well as some
|
1092 |
-
* convenience methods for parsing and validating HTTP responses.
|
1093 |
-
*
|
1094 |
-
* @package Zend_Http
|
1095 |
-
* @subpackage Response
|
1096 |
-
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
1097 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
1098 |
-
*/
|
1099 |
-
class Ait_Zend_Http_Response
|
1100 |
-
{
|
1101 |
-
/**
|
1102 |
-
* List of all known HTTP response codes - used by responseCodeAsText() to
|
1103 |
-
* translate numeric codes to messages.
|
1104 |
-
*
|
1105 |
-
* @var array
|
1106 |
-
*/
|
1107 |
-
protected static $messages = array(
|
1108 |
-
// Informational 1xx
|
1109 |
-
100 => 'Continue',
|
1110 |
-
101 => 'Switching Protocols',
|
1111 |
-
|
1112 |
-
// Success 2xx
|
1113 |
-
200 => 'OK',
|
1114 |
-
201 => 'Created',
|
1115 |
-
202 => 'Accepted',
|
1116 |
-
203 => 'Non-Authoritative Information',
|
1117 |
-
204 => 'No Content',
|
1118 |
-
205 => 'Reset Content',
|
1119 |
-
206 => 'Partial Content',
|
1120 |
-
|
1121 |
-
// Redirection 3xx
|
1122 |
-
300 => 'Multiple Choices',
|
1123 |
-
301 => 'Moved Permanently',
|
1124 |
-
302 => 'Found', // 1.1
|
1125 |
-
303 => 'See Other',
|
1126 |
-
304 => 'Not Modified',
|
1127 |
-
305 => 'Use Proxy',
|
1128 |
-
// 306 is deprecated but reserved
|
1129 |
-
307 => 'Temporary Redirect',
|
1130 |
-
|
1131 |
-
// Client Error 4xx
|
1132 |
-
400 => 'Bad Request',
|
1133 |
-
401 => 'Unauthorized',
|
1134 |
-
402 => 'Payment Required',
|
1135 |
-
403 => 'Forbidden',
|
1136 |
-
404 => 'Not Found',
|
1137 |
-
405 => 'Method Not Allowed',
|
1138 |
-
406 => 'Not Acceptable',
|
1139 |
-
407 => 'Proxy Authentication Required',
|
1140 |
-
408 => 'Request Timeout',
|
1141 |
-
409 => 'Conflict',
|
1142 |
-
410 => 'Gone',
|
1143 |
-
411 => 'Length Required',
|
1144 |
-
412 => 'Precondition Failed',
|
1145 |
-
413 => 'Request Entity Too Large',
|
1146 |
-
414 => 'Request-URI Too Long',
|
1147 |
-
415 => 'Unsupported Media Type',
|
1148 |
-
416 => 'Requested Range Not Satisfiable',
|
1149 |
-
417 => 'Expectation Failed',
|
1150 |
-
|
1151 |
-
// Server Error 5xx
|
1152 |
-
500 => 'Internal Server Error',
|
1153 |
-
501 => 'Not Implemented',
|
1154 |
-
502 => 'Bad Gateway',
|
1155 |
-
503 => 'Service Unavailable',
|
1156 |
-
504 => 'Gateway Timeout',
|
1157 |
-
505 => 'HTTP Version Not Supported',
|
1158 |
-
509 => 'Bandwidth Limit Exceeded'
|
1159 |
-
);
|
1160 |
-
|
1161 |
-
/**
|
1162 |
-
* The HTTP version (1.0, 1.1)
|
1163 |
-
*
|
1164 |
-
* @var string
|
1165 |
-
*/
|
1166 |
-
protected $version;
|
1167 |
-
|
1168 |
-
/**
|
1169 |
-
* The HTTP response code
|
1170 |
-
*
|
1171 |
-
* @var int
|
1172 |
-
*/
|
1173 |
-
protected $code;
|
1174 |
-
|
1175 |
-
/**
|
1176 |
-
* The HTTP response code as string
|
1177 |
-
* (e.g. 'Not Found' for 404 or 'Internal Server Error' for 500)
|
1178 |
-
*
|
1179 |
-
* @var string
|
1180 |
-
*/
|
1181 |
-
protected $message;
|
1182 |
-
|
1183 |
-
/**
|
1184 |
-
* The HTTP response headers array
|
1185 |
-
*
|
1186 |
-
* @var array
|
1187 |
-
*/
|
1188 |
-
protected $headers = array();
|
1189 |
-
|
1190 |
-
/**
|
1191 |
-
* The HTTP response body
|
1192 |
-
*
|
1193 |
-
* @var string
|
1194 |
-
*/
|
1195 |
-
protected $body;
|
1196 |
-
|
1197 |
-
/**
|
1198 |
-
* HTTP response constructor
|
1199 |
-
*
|
1200 |
-
* In most cases, you would use Zend_Http_Response::fromString to parse an HTTP
|
1201 |
-
* response string and create a new Zend_Http_Response object.
|
1202 |
-
*
|
1203 |
-
* NOTE: The constructor no longer accepts nulls or empty values for the code and
|
1204 |
-
* headers and will throw an exception if the passed values do not form a valid HTTP
|
1205 |
-
* responses.
|
1206 |
-
*
|
1207 |
-
* If no message is passed, the message will be guessed according to the response code.
|
1208 |
-
*
|
1209 |
-
* @param int $code Response code (200, 404, ...)
|
1210 |
-
* @param array $headers Headers array
|
1211 |
-
* @param string $body Response body
|
1212 |
-
* @param string $version HTTP version
|
1213 |
-
* @param string $message Response code as text
|
1214 |
-
* @throws Ait_Zend_Http_Exception
|
1215 |
-
*/
|
1216 |
-
public function __construct($code, $headers, $body = null, $version = '1.1', $message = null)
|
1217 |
-
{
|
1218 |
-
// Make sure the response code is valid and set it
|
1219 |
-
if (self::responseCodeAsText($code) === null) {
|
1220 |
-
throw new Ait_Zend_Http_Exception("{$code} is not a valid HTTP response code");
|
1221 |
-
}
|
1222 |
-
|
1223 |
-
$this->code = $code;
|
1224 |
-
|
1225 |
-
// Make sure we got valid headers and set them
|
1226 |
-
if (! is_array($headers)) {
|
1227 |
-
throw new Ait_Zend_Http_Exception('No valid headers were passed');
|
1228 |
-
}
|
1229 |
-
|
1230 |
-
foreach ($headers as $name => $value) {
|
1231 |
-
if (is_int($name))
|
1232 |
-
list($name, $value) = explode(": ", $value, 1);
|
1233 |
-
|
1234 |
-
$this->headers[ucwords(strtolower($name))] = $value;
|
1235 |
-
}
|
1236 |
-
|
1237 |
-
// Set the body
|
1238 |
-
$this->body = $body;
|
1239 |
-
|
1240 |
-
// Set the HTTP version
|
1241 |
-
if (! preg_match('|^\d\.\d$|', $version)) {
|
1242 |
-
throw new Ait_Zend_Http_Exception("Invalid HTTP response version: $version");
|
1243 |
-
}
|
1244 |
-
|
1245 |
-
$this->version = $version;
|
1246 |
-
|
1247 |
-
// If we got the response message, set it. Else, set it according to
|
1248 |
-
// the response code
|
1249 |
-
if (is_string($message)) {
|
1250 |
-
$this->message = $message;
|
1251 |
-
} else {
|
1252 |
-
$this->message = self::responseCodeAsText($code);
|
1253 |
-
}
|
1254 |
-
}
|
1255 |
-
|
1256 |
-
/**
|
1257 |
-
* Check whether the response is an error
|
1258 |
-
*
|
1259 |
-
* @return boolean
|
1260 |
-
*/
|
1261 |
-
public function isError()
|
1262 |
-
{
|
1263 |
-
$restype = floor($this->code / 100);
|
1264 |
-
if ($restype == 4 || $restype == 5) {
|
1265 |
-
return true;
|
1266 |
-
}
|
1267 |
-
|
1268 |
-
return false;
|
1269 |
-
}
|
1270 |
-
|
1271 |
-
/**
|
1272 |
-
* Check whether the response in successful
|
1273 |
-
*
|
1274 |
-
* @return boolean
|
1275 |
-
*/
|
1276 |
-
public function isSuccessful()
|
1277 |
-
{
|
1278 |
-
$restype = floor($this->code / 100);
|
1279 |
-
if ($restype == 2 || $restype == 1) { // Shouldn't 3xx count as success as well ???
|
1280 |
-
return true;
|
1281 |
-
}
|
1282 |
-
|
1283 |
-
return false;
|
1284 |
-
}
|
1285 |
-
|
1286 |
-
/**
|
1287 |
-
* Check whether the response is a redirection
|
1288 |
-
*
|
1289 |
-
* @return boolean
|
1290 |
-
*/
|
1291 |
-
public function isRedirect()
|
1292 |
-
{
|
1293 |
-
$restype = floor($this->code / 100);
|
1294 |
-
if ($restype == 3) {
|
1295 |
-
return true;
|
1296 |
-
}
|
1297 |
-
|
1298 |
-
return false;
|
1299 |
-
}
|
1300 |
-
|
1301 |
-
/**
|
1302 |
-
* Get the response body as string
|
1303 |
-
*
|
1304 |
-
* This method returns the body of the HTTP response (the content), as it
|
1305 |
-
* should be in it's readable version - that is, after decoding it (if it
|
1306 |
-
* was decoded), deflating it (if it was gzip compressed), etc.
|
1307 |
-
*
|
1308 |
-
* If you want to get the raw body (as transfered on wire) use
|
1309 |
-
* $this->getRawBody() instead.
|
1310 |
-
*
|
1311 |
-
* @return string
|
1312 |
-
*/
|
1313 |
-
public function getBody()
|
1314 |
-
{
|
1315 |
-
$body = '';
|
1316 |
-
|
1317 |
-
// Decode the body if it was transfer-encoded
|
1318 |
-
switch ($this->getHeader('transfer-encoding')) {
|
1319 |
-
|
1320 |
-
// Handle chunked body
|
1321 |
-
case 'chunked':
|
1322 |
-
$body = self::decodeChunkedBody($this->body);
|
1323 |
-
break;
|
1324 |
-
|
1325 |
-
// No transfer encoding, or unknown encoding extension:
|
1326 |
-
// return body as is
|
1327 |
-
default:
|
1328 |
-
$body = $this->body;
|
1329 |
-
break;
|
1330 |
-
}
|
1331 |
-
|
1332 |
-
// Decode any content-encoding (gzip or deflate) if needed
|
1333 |
-
switch (strtolower($this->getHeader('content-encoding'))) {
|
1334 |
-
|
1335 |
-
// Handle gzip encoding
|
1336 |
-
case 'gzip':
|
1337 |
-
$body = self::decodeGzip($body);
|
1338 |
-
break;
|
1339 |
-
|
1340 |
-
// Handle deflate encoding
|
1341 |
-
case 'deflate':
|
1342 |
-
$body = self::decodeDeflate($body);
|
1343 |
-
break;
|
1344 |
-
|
1345 |
-
default:
|
1346 |
-
break;
|
1347 |
-
}
|
1348 |
-
|
1349 |
-
return $body;
|
1350 |
-
}
|
1351 |
-
|
1352 |
-
/**
|
1353 |
-
* Get the raw response body (as transfered "on wire") as string
|
1354 |
-
*
|
1355 |
-
* If the body is encoded (with Transfer-Encoding, not content-encoding -
|
1356 |
-
* IE "chunked" body), gzip compressed, etc. it will not be decoded.
|
1357 |
-
*
|
1358 |
-
* @return string
|
1359 |
-
*/
|
1360 |
-
public function getRawBody()
|
1361 |
-
{
|
1362 |
-
return $this->body;
|
1363 |
-
}
|
1364 |
-
|
1365 |
-
/**
|
1366 |
-
* Get the HTTP version of the response
|
1367 |
-
*
|
1368 |
-
* @return string
|
1369 |
-
*/
|
1370 |
-
public function getVersion()
|
1371 |
-
{
|
1372 |
-
return $this->version;
|
1373 |
-
}
|
1374 |
-
|
1375 |
-
/**
|
1376 |
-
* Get the HTTP response status code
|
1377 |
-
*
|
1378 |
-
* @return int
|
1379 |
-
*/
|
1380 |
-
public function getStatus()
|
1381 |
-
{
|
1382 |
-
return $this->code;
|
1383 |
-
}
|
1384 |
-
|
1385 |
-
/**
|
1386 |
-
* Return a message describing the HTTP response code
|
1387 |
-
* (Eg. "OK", "Not Found", "Moved Permanently")
|
1388 |
-
*
|
1389 |
-
* @return string
|
1390 |
-
*/
|
1391 |
-
public function getMessage()
|
1392 |
-
{
|
1393 |
-
return $this->message;
|
1394 |
-
}
|
1395 |
-
|
1396 |
-
/**
|
1397 |
-
* Get the response headers
|
1398 |
-
*
|
1399 |
-
* @return array
|
1400 |
-
*/
|
1401 |
-
public function getHeaders()
|
1402 |
-
{
|
1403 |
-
return $this->headers;
|
1404 |
-
}
|
1405 |
-
|
1406 |
-
/**
|
1407 |
-
* Get a specific header as string, or null if it is not set
|
1408 |
-
*
|
1409 |
-
* @param string$header
|
1410 |
-
* @return string|array|null
|
1411 |
-
*/
|
1412 |
-
public function getHeader($header)
|
1413 |
-
{
|
1414 |
-
$header = ucwords(strtolower($header));
|
1415 |
-
if (! is_string($header) || ! isset($this->headers[$header])) return null;
|
1416 |
-
|
1417 |
-
return $this->headers[$header];
|
1418 |
-
}
|
1419 |
-
|
1420 |
-
/**
|
1421 |
-
* Get all headers as string
|
1422 |
-
*
|
1423 |
-
* @param boolean $status_line Whether to return the first status line (IE "HTTP 200 OK")
|
1424 |
-
* @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
|
1425 |
-
* @return string
|
1426 |
-
*/
|
1427 |
-
public function getHeadersAsString($status_line = true, $br = "\n")
|
1428 |
-
{
|
1429 |
-
$str = '';
|
1430 |
-
|
1431 |
-
if ($status_line) {
|
1432 |
-
$str = "HTTP/{$this->version} {$this->code} {$this->message}{$br}";
|
1433 |
-
}
|
1434 |
-
|
1435 |
-
// Iterate over the headers and stringify them
|
1436 |
-
foreach ($this->headers as $name => $value)
|
1437 |
-
{
|
1438 |
-
if (is_string($value))
|
1439 |
-
$str .= "{$name}: {$value}{$br}";
|
1440 |
-
|
1441 |
-
elseif (is_array($value)) {
|
1442 |
-
foreach ($value as $subval) {
|
1443 |
-
$str .= "{$name}: {$subval}{$br}";
|
1444 |
-
}
|
1445 |
-
}
|
1446 |
-
}
|
1447 |
-
|
1448 |
-
return $str;
|
1449 |
-
}
|
1450 |
-
|
1451 |
-
/**
|
1452 |
-
* Get the entire response as string
|
1453 |
-
*
|
1454 |
-
* @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
|
1455 |
-
* @return string
|
1456 |
-
*/
|
1457 |
-
public function asString($br = "\n")
|
1458 |
-
{
|
1459 |
-
return $this->getHeadersAsString(true, $br) . $br . $this->getRawBody();
|
1460 |
-
}
|
1461 |
-
|
1462 |
-
/**
|
1463 |
-
* A convenience function that returns a text representation of
|
1464 |
-
* HTTP response codes. Returns 'Unknown' for unknown codes.
|
1465 |
-
* Returns array of all codes, if $code is not specified.
|
1466 |
-
*
|
1467 |
-
* Conforms to HTTP/1.1 as defined in RFC 2616 (except for 'Unknown')
|
1468 |
-
* See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 for reference
|
1469 |
-
*
|
1470 |
-
* @param int $code HTTP response code
|
1471 |
-
* @param boolean $http11 Use HTTP version 1.1
|
1472 |
-
* @return string
|
1473 |
-
*/
|
1474 |
-
public static function responseCodeAsText($code = null, $http11 = true)
|
1475 |
-
{
|
1476 |
-
$messages = self::$messages;
|
1477 |
-
if (! $http11) $messages[302] = 'Moved Temporarily';
|
1478 |
-
|
1479 |
-
if ($code === null) {
|
1480 |
-
return $messages;
|
1481 |
-
} elseif (isset($messages[$code])) {
|
1482 |
-
return $messages[$code];
|
1483 |
-
} else {
|
1484 |
-
return 'Unknown';
|
1485 |
-
}
|
1486 |
-
}
|
1487 |
-
|
1488 |
-
/**
|
1489 |
-
* Extract the response code from a response string
|
1490 |
-
*
|
1491 |
-
* @param string $response_str
|
1492 |
-
* @return int
|
1493 |
-
*/
|
1494 |
-
public static function extractCode($response_str)
|
1495 |
-
{
|
1496 |
-
preg_match("|^HTTP/[\d\.x]+ (\d+)|", $response_str, $m);
|
1497 |
-
|
1498 |
-
if (isset($m[1])) {
|
1499 |
-
return (int) $m[1];
|
1500 |
-
} else {
|
1501 |
-
return false;
|
1502 |
-
}
|
1503 |
-
}
|
1504 |
-
|
1505 |
-
/**
|
1506 |
-
* Extract the HTTP message from a response
|
1507 |
-
*
|
1508 |
-
* @param string $response_str
|
1509 |
-
* @return string
|
1510 |
-
*/
|
1511 |
-
public static function extractMessage($response_str)
|
1512 |
-
{
|
1513 |
-
preg_match("|^HTTP/[\d\.x]+ \d+ ([^\r\n]+)|", $response_str, $m);
|
1514 |
-
|
1515 |
-
if (isset($m[1])) {
|
1516 |
-
return $m[1];
|
1517 |
-
} else {
|
1518 |
-
return false;
|
1519 |
-
}
|
1520 |
-
}
|
1521 |
-
|
1522 |
-
/**
|
1523 |
-
* Extract the HTTP version from a response
|
1524 |
-
*
|
1525 |
-
* @param string $response_str
|
1526 |
-
* @return string
|
1527 |
-
*/
|
1528 |
-
public static function extractVersion($response_str)
|
1529 |
-
{
|
1530 |
-
preg_match("|^HTTP/([\d\.x]+) \d+|", $response_str, $m);
|
1531 |
-
|
1532 |
-
if (isset($m[1])) {
|
1533 |
-
return $m[1];
|
1534 |
-
} else {
|
1535 |
-
return false;
|
1536 |
-
}
|
1537 |
-
}
|
1538 |
-
|
1539 |
-
/**
|
1540 |
-
* Extract the headers from a response string
|
1541 |
-
*
|
1542 |
-
* @param string $response_str
|
1543 |
-
* @return array
|
1544 |
-
*/
|
1545 |
-
public static function extractHeaders($response_str)
|
1546 |
-
{
|
1547 |
-
$headers = array();
|
1548 |
-
|
1549 |
-
// First, split body and headers
|
1550 |
-
$parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
|
1551 |
-
if (! $parts[0]) return $headers;
|
1552 |
-
|
1553 |
-
// Split headers part to lines
|
1554 |
-
$lines = explode("\n", $parts[0]);
|
1555 |
-
unset($parts);
|
1556 |
-
$last_header = null;
|
1557 |
-
|
1558 |
-
foreach($lines as $line) {
|
1559 |
-
$line = trim($line, "\r\n");
|
1560 |
-
if ($line == "") break;
|
1561 |
-
|
1562 |
-
if (preg_match("|^([\w-]+):\s+(.+)|", $line, $m)) {
|
1563 |
-
unset($last_header);
|
1564 |
-
$h_name = strtolower($m[1]);
|
1565 |
-
$h_value = $m[2];
|
1566 |
-
|
1567 |
-
if (isset($headers[$h_name])) {
|
1568 |
-
if (! is_array($headers[$h_name])) {
|
1569 |
-
$headers[$h_name] = array($headers[$h_name]);
|
1570 |
-
}
|
1571 |
-
|
1572 |
-
$headers[$h_name][] = $h_value;
|
1573 |
-
} else {
|
1574 |
-
$headers[$h_name] = $h_value;
|
1575 |
-
}
|
1576 |
-
$last_header = $h_name;
|
1577 |
-
} elseif (preg_match("|^\s+(.+)$|", $line, $m) && $last_header !== null) {
|
1578 |
-
if (is_array($headers[$last_header])) {
|
1579 |
-
end($headers[$last_header]);
|
1580 |
-
$last_header_key = key($headers[$last_header]);
|
1581 |
-
$headers[$last_header][$last_header_key] .= $m[1];
|
1582 |
-
} else {
|
1583 |
-
$headers[$last_header] .= $m[1];
|
1584 |
-
}
|
1585 |
-
}
|
1586 |
-
}
|
1587 |
-
|
1588 |
-
return $headers;
|
1589 |
-
}
|
1590 |
-
|
1591 |
-
/**
|
1592 |
-
* Extract the body from a response string
|
1593 |
-
*
|
1594 |
-
* @param string $response_str
|
1595 |
-
* @return string
|
1596 |
-
*/
|
1597 |
-
public static function extractBody($response_str)
|
1598 |
-
{
|
1599 |
-
$parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
|
1600 |
-
if (isset($parts[1])) {
|
1601 |
-
return $parts[1];
|
1602 |
-
}
|
1603 |
-
return '';
|
1604 |
-
}
|
1605 |
-
|
1606 |
-
/**
|
1607 |
-
* Decode a "chunked" transfer-encoded body and return the decoded text
|
1608 |
-
*
|
1609 |
-
* @param string $body
|
1610 |
-
* @return string
|
1611 |
-
*/
|
1612 |
-
public static function decodeChunkedBody($body)
|
1613 |
-
{
|
1614 |
-
$decBody = '';
|
1615 |
-
|
1616 |
-
while (preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", trim($body), $m)) {
|
1617 |
-
$length = hexdec(trim($m[1]));
|
1618 |
-
$cut = strlen($m[0]);
|
1619 |
-
|
1620 |
-
$decBody .= substr($body, $cut, $length);
|
1621 |
-
$body = substr($body, $cut + $length + 2);
|
1622 |
-
}
|
1623 |
-
|
1624 |
-
return $decBody;
|
1625 |
-
}
|
1626 |
-
|
1627 |
-
/**
|
1628 |
-
* Decode a gzip encoded message (when Content-encoding = gzip)
|
1629 |
-
*
|
1630 |
-
* Currently requires PHP with zlib support
|
1631 |
-
*
|
1632 |
-
* @param string $body
|
1633 |
-
* @return string
|
1634 |
-
*/
|
1635 |
-
public static function decodeGzip($body)
|
1636 |
-
{
|
1637 |
-
if (! function_exists('gzinflate')) {
|
1638 |
-
throw new Ait_Zend_Http_Exception('Unable to decode gzipped response ' .
|
1639 |
-
'body: perhaps the zlib extension is not loaded?');
|
1640 |
-
}
|
1641 |
-
|
1642 |
-
return gzinflate(substr($body, 10));
|
1643 |
-
}
|
1644 |
-
|
1645 |
-
/**
|
1646 |
-
* Decode a zlib deflated message (when Content-encoding = deflate)
|
1647 |
-
*
|
1648 |
-
* Currently requires PHP with zlib support
|
1649 |
-
*
|
1650 |
-
* @param string $body
|
1651 |
-
* @return string
|
1652 |
-
*/
|
1653 |
-
public static function decodeDeflate($body)
|
1654 |
-
{
|
1655 |
-
if (! function_exists('gzuncompress')) {
|
1656 |
-
throw new Ait_Zend_Http_Exception('Unable to decode deflated response ' .
|
1657 |
-
'body: perhaps the zlib extension is not loaded?');
|
1658 |
-
}
|
1659 |
-
|
1660 |
-
return gzuncompress($body);
|
1661 |
-
}
|
1662 |
-
|
1663 |
-
/**
|
1664 |
-
* Create a new Zend_Http_Response object from a string
|
1665 |
-
*
|
1666 |
-
* @param string $response_str
|
1667 |
-
* @return Ait_Zend_Http_Response
|
1668 |
-
*/
|
1669 |
-
public static function fromString($response_str)
|
1670 |
-
{
|
1671 |
-
$code = self::extractCode($response_str);
|
1672 |
-
$headers = self::extractHeaders($response_str);
|
1673 |
-
$body = self::extractBody($response_str);
|
1674 |
-
$version = self::extractVersion($response_str);
|
1675 |
-
$message = self::extractMessage($response_str);
|
1676 |
-
|
1677 |
-
return new Ait_Zend_Http_Response($code, $headers, $body, $version, $message);
|
1678 |
-
}
|
1679 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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