Version Notes
changes:
- fixed some connection issues
Download this release
Release Info
Developer | Juraj Simon |
Extension | Liveagent |
Version | 2.5.10 |
Comparing to | |
See all releases |
Code changes from version 2.5.9 to 2.5.10
- app/code/local/Qualityunit/Liveagent/_Block/Account.php +125 -0
- app/code/local/Qualityunit/Liveagent/_Block/Base.php +55 -0
- app/code/local/Qualityunit/Liveagent/_Block/Buttoncode.php +112 -0
- app/code/local/Qualityunit/Liveagent/_Block/Signup.php +124 -0
- app/code/local/Qualityunit/Liveagent/_Block/Waiting.php +72 -0
- app/code/local/Qualityunit/Liveagent/{Helper → _Helper}/.Auth.php.swp +0 -0
- app/code/local/Qualityunit/Liveagent/_Helper/Account.php +15 -0
- app/code/local/Qualityunit/Liveagent/_Helper/Auth.php +90 -0
- app/code/local/Qualityunit/Liveagent/_Helper/Base.php +56 -0
- app/code/local/Qualityunit/Liveagent/_Helper/Data.php +23 -0
- app/code/local/Qualityunit/Liveagent/_Helper/PhpApi.php +4303 -0
- app/code/local/Qualityunit/Liveagent/_Helper/Settings.php +146 -0
- app/code/local/Qualityunit/Liveagent/_Helper/Signup.php +47 -0
- app/code/local/Qualityunit/Liveagent/_controllers/Adminhtml/LiveagentController.php +334 -0
- app/code/local/Qualityunit/Liveagent/_controllers/IndexController.php +8 -0
- package.xml +4 -4
app/code/local/Qualityunit/Liveagent/_Block/Account.php
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Qualityunit_Liveagent_Block_Account extends Qualityunit_Liveagent_Block_Base {
|
4 |
+
|
5 |
+
const SAVE_ACCOUNT_SETTINGS_ACTION_FLAG = 'sas';
|
6 |
+
const CANCEL_ACCOUNT_ACTION_FLAG = 'c';
|
7 |
+
const CREATE_ACCOUNT_ACTION_FLAF = 's';
|
8 |
+
const CHANGE_ACCOUNT_ACTION_FLAG = 'h';
|
9 |
+
|
10 |
+
public function _prepareLayout() {
|
11 |
+
parent::_prepareLayout();
|
12 |
+
$settings = new Qualityunit_Liveagent_Helper_Settings();
|
13 |
+
$this->assignVariable('dialogCaption', Mage::helper('adminhtml')->__('LiveAgent - Free live chat and helpdesk plugin for Magento'));
|
14 |
+
$this->assignVariable('submitCaption', Mage::helper('adminhtml')->__('Save Account Settings'));
|
15 |
+
$this->assignVariable('settingsSection', Mage::helper('adminhtml')->__('Account Settings'));
|
16 |
+
$this->assignVariable('beforeDeleteQuestion', Mage::helper('adminhtml')->__('Are you sure you want to cancel your account?'));
|
17 |
+
$this->assignVariable('formKey', Mage::getSingleton('core/session')->getFormKey());
|
18 |
+
$this->assignVariable('saveUrlAction', $this->getUrl('*/*/post'));
|
19 |
+
$this->assignVariable('cancelUrlAction', $this->getUrl('*/*/index', array('key' => $this->getRequest()->get('key'), 'action' => self::CANCEL_ACCOUNT_ACTION_FLAG)));
|
20 |
+
$this->assignVariable('urlLabel', Mage::helper('adminhtml')->__('Url')) . ':';
|
21 |
+
$this->assignVariable('urlHelp', Mage::helper('adminhtml')->__('Url where your LiveAgent installation is located'));
|
22 |
+
$this->assignVariable('laOwnerEmailHelp', Mage::helper('adminhtml')->__('Username which you use to login to your Live Agnet'));
|
23 |
+
$this->assignVariable('nameLabel', Mage::helper('adminhtml')->__('Username')) . ':';
|
24 |
+
if ($settings->useApiKey()) {
|
25 |
+
$this->assignVariable('passwordLabel', Mage::helper('adminhtml')->__('Api key')) . ':';
|
26 |
+
$this->assignVariable('laOwnerPasswordHelp', Mage::helper('adminhtml')->__('Your REST api key'));
|
27 |
+
} else {
|
28 |
+
$this->assignVariable('passwordLabel', Mage::helper('adminhtml')->__('Password')) . ':';
|
29 |
+
$this->assignVariable('laOwnerPasswordHelp', Mage::helper('adminhtml')->__('Your password'));
|
30 |
+
}
|
31 |
+
|
32 |
+
$this->assignVariable('cancelLink', Mage::helper('adminhtml')->__('Cancel account'));
|
33 |
+
$this->assignVariable('cancelHelp', Mage::helper('adminhtml')->__('this will clear all your existing account settings and offer you to create a new free account'));
|
34 |
+
$this->assignVariable('contactLink', Mage::helper('adminhtml')->__('contact us'));
|
35 |
+
$this->assignVariable('contactHelp', Mage::helper('adminhtml')->__('Do you need any help with this plugin? Feel free to'));
|
36 |
+
$this->assignVariable(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME, $this->getInputBox(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME, ''));
|
37 |
+
$this->assignVariable(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME, $this->getInputBox(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME, ''));
|
38 |
+
$this->assignVariable(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME, $this->getPasswordBox(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME, ''));
|
39 |
+
$this->assignVariable('saveActionSettingsFlag', self::SAVE_ACCOUNT_SETTINGS_ACTION_FLAG);
|
40 |
+
}
|
41 |
+
|
42 |
+
protected function getPasswordBox($name, $value) {
|
43 |
+
$params = $this->getRequest()->getParams();
|
44 |
+
if (isset($params[$name])) {
|
45 |
+
return parent::getPasswordBox($name, base64_decode(trim($this->getRequest()->getParam($name))));
|
46 |
+
}
|
47 |
+
$settings = new Qualityunit_Liveagent_Helper_Settings();
|
48 |
+
return parent::getPasswordBox($name, $settings->getOption($name));
|
49 |
+
}
|
50 |
+
|
51 |
+
protected function getInputBox($name, $value) {
|
52 |
+
$params = $this->getRequest()->getParams();
|
53 |
+
if (isset($params[$name])) {
|
54 |
+
return parent::getInputBox($name, base64_decode(trim($this->getRequest()->getParam($name))));
|
55 |
+
}
|
56 |
+
$settings = new Qualityunit_Liveagent_Helper_Settings();
|
57 |
+
return parent::getInputBox($name, $settings->getOption($name));
|
58 |
+
}
|
59 |
+
|
60 |
+
protected function getTemplateString() {
|
61 |
+
return '
|
62 |
+
<script type="text/javascript">
|
63 |
+
var cancelMyAccount = function() {
|
64 |
+
if (confirm(\'{beforeDeleteQuestion}\')) {
|
65 |
+
setLocation(\'{cancelUrlAction}\')
|
66 |
+
}
|
67 |
+
}
|
68 |
+
</script>
|
69 |
+
<form id="configForm" name="edit_form" action="{saveUrlAction}" method="post">
|
70 |
+
<input name="form_key" type="hidden" value="{formKey}" />
|
71 |
+
<input name="action" type="hidden" value="{saveActionSettingsFlag}"/>
|
72 |
+
<div class="content-header">
|
73 |
+
<table cellspacing="0">
|
74 |
+
<tbody><tr>
|
75 |
+
<td style="width:50%;"><h3 class="icon-head head-promo-catalog">{dialogCaption}</h3></td>
|
76 |
+
<td class="form-buttons"><button id="id_5806f3a306fa79f4340cb58c1d190ff5" type="button" class="scalable save" onclick="configForm.submit()" style=""><span>{submitCaption}</span></button></td>
|
77 |
+
</tr>
|
78 |
+
</tbody>
|
79 |
+
</table>
|
80 |
+
</div>
|
81 |
+
<div class="entry-edit">
|
82 |
+
<fieldset>
|
83 |
+
{contactHelp} <a href="http://support.qualityunit.com/submit_ticket" target="_blank">{contactLink}</a>.
|
84 |
+
</fieldset>
|
85 |
+
</div>
|
86 |
+
<div class="entry-edit">
|
87 |
+
<div class="entry-edit-head"><h4>{settingsSection}</h4></div>
|
88 |
+
<fieldset>
|
89 |
+
<table cellspacing="0" class="form-list">
|
90 |
+
<colgroup class="label"></colgroup>
|
91 |
+
<colgroup class="value"></colgroup>
|
92 |
+
<colgroup class="scope-label"></colgroup>
|
93 |
+
<colgroup class=""></colgroup>
|
94 |
+
<tbody>
|
95 |
+
<tr id="row_la_url">
|
96 |
+
<td class="label"><label for="row_la_url">{urlLabel}</label></td>
|
97 |
+
<td class="value">{la-url}
|
98 |
+
<p class="note"><span>{urlHelp}</span></p></td>
|
99 |
+
<td class="scope-label"></td><td></td>
|
100 |
+
</tr>
|
101 |
+
<tr id="row_owner_email">
|
102 |
+
<td class="label"><label for="row_owner_email">{nameLabel}</label></td>
|
103 |
+
<td class="value">{la-owner-email}
|
104 |
+
<p class="note"><span>{laOwnerEmailHelp}</span></p></td>
|
105 |
+
<td class="scope-label"></td><td></td>
|
106 |
+
</tr>
|
107 |
+
<tr id="row_owner_pass">
|
108 |
+
<td class="label"><label for="row_owner_pass">{passwordLabel}</label></td>
|
109 |
+
<td class="value">{la-owner-password}
|
110 |
+
<p class="note"><span>{laOwnerPasswordHelp}</span></p></td>
|
111 |
+
<td class="scope-label"></td><td></td>
|
112 |
+
</tr>
|
113 |
+
<tr>
|
114 |
+
<td colspan="4" class="scope-label"><button onclick="cancelMyAccount()" type="button" class="scalable delete"><span>{cancelLink}</span></button> {cancelHelp}</td>
|
115 |
+
</tr>
|
116 |
+
<tr>
|
117 |
+
<td colspan="4" class="scope-label"></td>
|
118 |
+
</tr>
|
119 |
+
</tbody>
|
120 |
+
</table>
|
121 |
+
</fieldset>
|
122 |
+
</div>
|
123 |
+
';
|
124 |
+
}
|
125 |
+
}
|
app/code/local/Qualityunit/Liveagent/_Block/Base.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Qualityunit_Liveagent_Block_Base extends Mage_Core_Block_Template {
|
4 |
+
|
5 |
+
protected $variables = array();
|
6 |
+
|
7 |
+
protected function curPageURL() {
|
8 |
+
$pageURL = 'http';
|
9 |
+
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
|
10 |
+
$pageURL .= "s";
|
11 |
+
}
|
12 |
+
$pageURL .= "://";
|
13 |
+
if ($_SERVER["SERVER_PORT"] != "80") {
|
14 |
+
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
|
15 |
+
} else {
|
16 |
+
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
|
17 |
+
}
|
18 |
+
|
19 |
+
$pageURL = preg_replace("/\?.*$/", "", $pageURL);
|
20 |
+
|
21 |
+
return $pageURL;
|
22 |
+
}
|
23 |
+
|
24 |
+
protected function getPasswordBox($name, $value) {
|
25 |
+
return '<input type="password" id="'.$name.'" name="'.$name.'" value="'.$value.'" class=" input-text" />';
|
26 |
+
}
|
27 |
+
|
28 |
+
protected function getTextArea($name, $value, $rows = 1, $cols = 10, $additionalClass = '') {
|
29 |
+
return '<textarea rows="'.$rows.'" cols="'.$cols.'" id="'.$name.'" name="'.$name.'" class="'.$additionalClass.'" />'.$value.'</textarea>';
|
30 |
+
}
|
31 |
+
|
32 |
+
protected function getInputBox($name, $value) {
|
33 |
+
return '<input type="text" id="'.$name.'" name="'.$name.'" value="'.$value.'" class=" input-text" />';
|
34 |
+
}
|
35 |
+
|
36 |
+
protected function _toHtml() {
|
37 |
+
$html = $this->getTemplateString();
|
38 |
+
foreach ($this->variables as $name => $value) {
|
39 |
+
$html = str_replace('{'.$name.'}', $value, $html);
|
40 |
+
}
|
41 |
+
return $html;
|
42 |
+
}
|
43 |
+
|
44 |
+
protected function _prepareLayout() {
|
45 |
+
parent::_prepareLayout();
|
46 |
+
}
|
47 |
+
|
48 |
+
protected function assignVariable($name, $value) {
|
49 |
+
$this->variables[$name] = $value;
|
50 |
+
}
|
51 |
+
|
52 |
+
protected function getTemplateString() {
|
53 |
+
return '';
|
54 |
+
}
|
55 |
+
}
|
app/code/local/Qualityunit/Liveagent/_Block/Buttoncode.php
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Qualityunit_Liveagent_Block_Buttoncode extends Qualityunit_Liveagent_Block_Base {
|
4 |
+
|
5 |
+
const SAVE_BUTTON_CODE_ACTION_FLAG = 'sb';
|
6 |
+
|
7 |
+
public function _prepareLayout() {
|
8 |
+
$settings = new Qualityunit_Liveagent_Helper_Settings();
|
9 |
+
parent::_prepareLayout();
|
10 |
+
$this->assignVariable('dialogCaption', Mage::helper('adminhtml')->__('LiveAgent - Free live chat and helpdesk plugin for Magento'));
|
11 |
+
$this->assignVariable('submitCaption', Mage::helper('adminhtml')->__('Save'));
|
12 |
+
$this->assignVariable('formKey', Mage::getSingleton('core/session')->getFormKey());
|
13 |
+
$this->assignVariable('saveUrlAction', $this->getUrl('*/*/post'));
|
14 |
+
$settings = new Qualityunit_Liveagent_Helper_Settings();
|
15 |
+
$code = htmlentities($settings->getOption(Qualityunit_Liveagent_Helper_Settings::BUTTON_CODE));
|
16 |
+
$this->assignVariable('la-config-button-code', $this->getTextArea('la-config-button-code', $code, 10 ,100, ' textarea'));
|
17 |
+
$this->assignVariable('buttonCodeLabel', Mage::helper('adminhtml')->__('Button code'));
|
18 |
+
$this->assignVariable('buttonCodeHelp', Mage::helper('adminhtml')->__('Place here the code from your LiveAgent admin panel'));
|
19 |
+
$this->assignVariable('saveButtonCodeFlag', self::SAVE_BUTTON_CODE_ACTION_FLAG);
|
20 |
+
$this->assignVariable('accountSectionLabel', Mage::helper('adminhtml')->__('Your account'));
|
21 |
+
$this->assignVariable('accountUrlLabel', Mage::helper('adminhtml')->__('Account url'));
|
22 |
+
$this->assignVariable('la-url', $settings->getOption(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME));
|
23 |
+
$this->assignVariable('loginLabel', Mage::helper('adminhtml')->__('login'));
|
24 |
+
$this->assignVariable('loginUrl', $this->getLoginUrl($settings));
|
25 |
+
$this->assignVariable('ChangeLabel', Mage::helper('adminhtml')->__('change'));
|
26 |
+
$this->assignVariable('ChangeUrl', $this->getUrl('*/*/index', array('key' => $this->getRequest()->get('key'), 'action' => Qualityunit_Liveagent_Block_Account::CHANGE_ACCOUNT_ACTION_FLAG)));
|
27 |
+
$this->assignVariable('integrationSectionLabel', Mage::helper('adminhtml')->__('Integration'));
|
28 |
+
$this->assignVariable('contactLink', Mage::helper('adminhtml')->__('contact us'));
|
29 |
+
$this->assignVariable('contactHelp', Mage::helper('adminhtml')->__('Do you need any help with this plugin? Feel free to'));
|
30 |
+
}
|
31 |
+
|
32 |
+
private function getLoginUrl(Qualityunit_Liveagent_Helper_Settings $settings) {
|
33 |
+
try {
|
34 |
+
$authToken = $settings->getOwnerAuthToken();
|
35 |
+
} catch (Exception $e) {
|
36 |
+
$authToken = '';
|
37 |
+
}
|
38 |
+
if ($authToken == '') {
|
39 |
+
$sessionId = $settings->getOwnerSessionId();
|
40 |
+
if ($sessionId != '') {
|
41 |
+
return $settings->getLiveAgentUrl() . '/agent/index.php?S='.$settings->getOwnerSessionId();
|
42 |
+
}
|
43 |
+
return $settings->getLiveAgentUrl() . '/agent/index.php';
|
44 |
+
}
|
45 |
+
return $settings->getLiveAgentUrl() . '/agent/index.php?AuthToken='.$authToken;
|
46 |
+
}
|
47 |
+
|
48 |
+
protected function getTemplateString() {
|
49 |
+
return '
|
50 |
+
<form id="configForm" name="edit_form" action="{saveUrlAction}" method="post">
|
51 |
+
<input name="form_key" type="hidden" value="{formKey}" />
|
52 |
+
<input name="action" type="hidden" value="{saveButtonCodeFlag}"/>
|
53 |
+
<div class="content-header">
|
54 |
+
<table cellspacing="0">
|
55 |
+
<tbody><tr>
|
56 |
+
<td style="width:50%;"><h3 class="icon-head head-promo-catalog">{dialogCaption}</h3></td>
|
57 |
+
<td class="form-buttons"><button id="id_5806f3a306fa79f4340cb58c1d190ff5" type="button" class="scalable save" onclick="configForm.submit()" style=""><span>{submitCaption}</span></button></td>
|
58 |
+
</tr>
|
59 |
+
</tbody>
|
60 |
+
</table>
|
61 |
+
</div>
|
62 |
+
<div class="entry-edit">
|
63 |
+
<fieldset>
|
64 |
+
{contactHelp} <a href="http://support.qualityunit.com/submit_ticket" target="_blank">{contactLink}</a>.
|
65 |
+
</fieldset>
|
66 |
+
</div>
|
67 |
+
<div class="entry-edit">
|
68 |
+
<div class="entry-edit-head"><h4>{accountSectionLabel}</h4></div>
|
69 |
+
<fieldset>
|
70 |
+
<table cellspacing="0" class="form-list">
|
71 |
+
<colgroup class="label"></colgroup>
|
72 |
+
<colgroup class="value"></colgroup>
|
73 |
+
<colgroup class="scope-label"></colgroup>
|
74 |
+
<colgroup class=""></colgroup>
|
75 |
+
<tbody>
|
76 |
+
<tr id="row_la_url">
|
77 |
+
<td class="label"><label for="row_la_url">{accountUrlLabel}:</label></td>
|
78 |
+
<td class="value">{la-url}
|
79 |
+
<a href="{loginUrl}" target="_balnk">{loginLabel}</a></button>
|
80 |
+
|
81 |
+
<a href="{ChangeUrl}">{ChangeLabel}</a></button>
|
82 |
+
</td>
|
83 |
+
<td class="scope-label"></td><td></td>
|
84 |
+
</tr>
|
85 |
+
</tbody>
|
86 |
+
</table>
|
87 |
+
</fieldset>
|
88 |
+
</div>
|
89 |
+
<div class="entry-edit">
|
90 |
+
<div class="entry-edit-head"><h4>{integrationSectionLabel}</h4></div>
|
91 |
+
<fieldset>
|
92 |
+
<table cellspacing="0" class="form-list">
|
93 |
+
<colgroup class="label"></colgroup>
|
94 |
+
<colgroup class="value"></colgroup>
|
95 |
+
<colgroup class="scope-label"></colgroup>
|
96 |
+
<colgroup class=""></colgroup>
|
97 |
+
<tbody>
|
98 |
+
<tr id="la-config-button-code">
|
99 |
+
<td class="label"><label for="la-config-button-code">{buttonCodeLabel}:</label></td>
|
100 |
+
<td class="value">{la-config-button-code}
|
101 |
+
<p class="note"><span>{buttonCodeHelp}</span></p>
|
102 |
+
</td>
|
103 |
+
<td class="scope-label"></td><td></td>
|
104 |
+
</tr>
|
105 |
+
</tbody>
|
106 |
+
</table>
|
107 |
+
</fieldset>
|
108 |
+
</div>
|
109 |
+
</form>
|
110 |
+
';
|
111 |
+
}
|
112 |
+
}
|
app/code/local/Qualityunit/Liveagent/_Block/Signup.php
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Qualityunit_Liveagent_Block_Signup extends Qualityunit_Liveagent_Block_Base {
|
4 |
+
|
5 |
+
const FULL_NAME_FIELD = 'la-full-name';
|
6 |
+
|
7 |
+
public function _prepareLayout() {
|
8 |
+
parent::_prepareLayout();
|
9 |
+
$this->assignVariable('dialogCaption', Mage::helper('adminhtml')->__('LiveAgent - Free live chat and helpdesk plugin for Magento'));
|
10 |
+
$this->assignVariable(self::FULL_NAME_FIELD, $this->getInputBox(self::FULL_NAME_FIELD, $this->getOwnerName()));
|
11 |
+
$this->assignVariable(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME, $this->getInputBox(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME, $this->getOwnerEmail()));
|
12 |
+
$this->assignVariable(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME, $this->getInputBox(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME, $this->getdomainOnly()));
|
13 |
+
$this->assignVariable('submitCaption', Mage::helper('adminhtml')->__('Create your Free account'));
|
14 |
+
$this->assignVariable('skipUrlAction', $this->getUrl('*/*/index', array('key' => $this->getRequest()->get('key'), 'action' => Qualityunit_Liveagent_Block_Account::CREATE_ACCOUNT_ACTION_FLAF)));
|
15 |
+
$this->assignVariable('registerUrlAction', $this->getUrl('*/*/post'));
|
16 |
+
$this->assignVariable('formKey', Mage::getSingleton('core/session')->getFormKey());
|
17 |
+
$this->assignVariable('fullNameLabel', Mage::helper('adminhtml')->__('Full name'));
|
18 |
+
$this->assignVariable('emailLabel', Mage::helper('adminhtml')->__('Email'));
|
19 |
+
$this->assignVariable('fullNameHelp', Mage::helper('adminhtml')->__('Your first name and last name'));
|
20 |
+
$this->assignVariable('urlLabel', Mage::helper('adminhtml')->__('Domain selection'));
|
21 |
+
$this->assignVariable('urlHelp', Mage::helper('adminhtml')->__('.ladesk.com'));
|
22 |
+
$this->assignVariable('termsLabel', Mage::helper('adminhtml')->__('By creating an account I agree to'));
|
23 |
+
$this->assignVariable('termsLink', Mage::helper('adminhtml')->__('Terms & Conditions'));
|
24 |
+
$this->assignVariable('skipLink', Mage::helper('adminhtml')->__('Skip this step, I already have an account'));
|
25 |
+
$this->assignVariable('settingsSection', Mage::helper('adminhtml')->__('New account'));
|
26 |
+
$this->assignVariable('pluginHelpText', Mage::helper('adminhtml')->__('We want you to enjoy the full functionality of LiveAgent with the free account. It does not limit the number of agents and you have the option to activate the most of available features.'));
|
27 |
+
}
|
28 |
+
|
29 |
+
private function getdomainOnly() {
|
30 |
+
$domain = preg_replace('/^(.*\.)?([^.]*\..*)$/', '$2', @$_SERVER['HTTP_HOST']);
|
31 |
+
if (trim($domain) == 'localhost') {
|
32 |
+
return '';
|
33 |
+
}
|
34 |
+
if (preg_match('/^[a-zA-Z0-9\-]+$/', $domain) === false) {
|
35 |
+
return '';
|
36 |
+
}
|
37 |
+
return $domain;
|
38 |
+
}
|
39 |
+
|
40 |
+
private function getOwnerName() {
|
41 |
+
try {
|
42 |
+
$user = Mage::getSingleton('admin/session')->getUser();
|
43 |
+
return $user->getFirstname() . ' ' . $user->getLastname();
|
44 |
+
} catch (Exception $e) {
|
45 |
+
Mage::log($e->getMessage(), Zend_Log::ERR);
|
46 |
+
return '';
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
private function getOwnerEmail() {
|
51 |
+
try {
|
52 |
+
$user = Mage::getSingleton('admin/session')->getUser();
|
53 |
+
return $user->getEmail();
|
54 |
+
} catch (Exception $e) {
|
55 |
+
Mage::log($e->getMessage(), Zend_Log::ERR);
|
56 |
+
return '';
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
protected function getTemplateString() {
|
61 |
+
return '
|
62 |
+
<script type="text/javascript">
|
63 |
+
var skipCreate = function() {
|
64 |
+
setLocation(\'{skipUrlAction}\')
|
65 |
+
}
|
66 |
+
</script>
|
67 |
+
<form id="configForm" name="edit_form" action="{registerUrlAction}" method="post">
|
68 |
+
<input name="form_key" type="hidden" value="{formKey}" />
|
69 |
+
<input name="action" type="hidden" value="r"/>
|
70 |
+
<div class="content-header">
|
71 |
+
<table cellspacing="0">
|
72 |
+
<tbody><tr>
|
73 |
+
<td style="width:50%;"><h3 class="icon-head head-promo-catalog">{dialogCaption}</h3></td>
|
74 |
+
<td class="form-buttons"><button id="id_5806f3a306fa79f4340cb58c1d190ff5" type="button" class="scalable save" onclick="configForm.submit()" style=""><span>{submitCaption}</span></button></td>
|
75 |
+
</tr>
|
76 |
+
</tbody>
|
77 |
+
</table>
|
78 |
+
</div>
|
79 |
+
<div class="entry-edit">
|
80 |
+
<fieldset>
|
81 |
+
{pluginHelpText}
|
82 |
+
</fieldset>
|
83 |
+
</div>
|
84 |
+
<div class="entry-edit">
|
85 |
+
<div class="entry-edit-head"><h4>{settingsSection}</h4></div>
|
86 |
+
<fieldset>
|
87 |
+
<table cellspacing="0" class="form-list">
|
88 |
+
<colgroup class="label"></colgroup>
|
89 |
+
<colgroup class="value"></colgroup>
|
90 |
+
<colgroup class="scope-label"></colgroup>
|
91 |
+
<colgroup class=""></colgroup>
|
92 |
+
<tbody>
|
93 |
+
<tr id="row_la_full_name">
|
94 |
+
<td class="label"><label for="row_la_full_name">{fullNameLabel}</label></td>
|
95 |
+
<td class="value">{la-full-name}
|
96 |
+
<p class="note"><span>{fullNameHelp}</span></p></td>
|
97 |
+
<td class="scope-label"></td><td></td>
|
98 |
+
</tr>
|
99 |
+
<tr id="row_owner_email">
|
100 |
+
<td class="label"><label for="row_owner_email">{emailLabel}</label></td>
|
101 |
+
<td class="value">{la-owner-email}</td>
|
102 |
+
<td class="scope-label"></td><td></td>
|
103 |
+
</tr>
|
104 |
+
<tr id="row_owner_pass">
|
105 |
+
<td class="label"><label for="row_owner_pass">{urlLabel}</label></td>
|
106 |
+
<td class="value">{la-url}</td>
|
107 |
+
<td class="scope-label">{urlHelp}</td><td></td>
|
108 |
+
</tr>
|
109 |
+
<tr>
|
110 |
+
<td colspan="4" class="scope-label">{termsLabel} <a target="_blank" href="http://www.qualityunit.com/liveagent/pricing/hosted/terms-and-conditions">{termsLink}</a>.</td>
|
111 |
+
</tr>
|
112 |
+
<tr>
|
113 |
+
<td colspan="4" class="scope-label"></td>
|
114 |
+
</tr>
|
115 |
+
<tr>
|
116 |
+
<td colspan="4" class="scope-label"><button onclick="skipCreate()" type="button" class="scalable "><span>{skipLink}</span></button></td>
|
117 |
+
</tr>
|
118 |
+
</tbody>
|
119 |
+
</table>
|
120 |
+
</fieldset>
|
121 |
+
</div>
|
122 |
+
';
|
123 |
+
}
|
124 |
+
}
|
app/code/local/Qualityunit/Liveagent/_Block/Waiting.php
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Qualityunit_Liveagent_Block_Waiting extends Qualityunit_Liveagent_Block_Base {
|
3 |
+
protected function _prepareLayout() {
|
4 |
+
parent::_prepareLayout();
|
5 |
+
$this->assignVariable('dialogCaption', Mage::helper('adminhtml')->__('LiveAgent - Free live chat and helpdesk plugin for Magento'));
|
6 |
+
$this->assignVariable('sectionCaption', Mage::helper('adminhtml')->__('Account Installation'));
|
7 |
+
$this->assignVariable('completeUrlAction', $this->getUrl('*/*/post'));
|
8 |
+
$this->assignVariable('installingText', Mage::helper('adminhtml')->__('Thank you! Your account will be online within next few minutes. Please wait...'));
|
9 |
+
$this->assignVariable('confEmailText', Mage::helper('adminhtml')->__('You should recieve confirmation email with your account credentials shortly.'));
|
10 |
+
$this->assignVariable('bitLongerText', Mage::helper('adminhtml')->__('Note: Sometimes account creation process may take a '));
|
11 |
+
$this->assignVariable('bitLongerLink', Mage::helper('adminhtml')->__('bit longer'));
|
12 |
+
$this->assignVariable('installText', Mage::helper('adminhtml')->__('Installing'));
|
13 |
+
$this->assignVariable('formKey', Mage::getSingleton('core/session')->getFormKey());
|
14 |
+
$this->assignVariable('initializingText', Mage::helper('adminhtml')->__('Initializing...'));
|
15 |
+
|
16 |
+
}
|
17 |
+
|
18 |
+
protected function getTemplateString() {
|
19 |
+
return '
|
20 |
+
<form id="liveagent_wait_form" name="edit_form" action="{completeUrlAction}" method="post">
|
21 |
+
<input name="form_key" type="hidden" value="{formKey}" />
|
22 |
+
<input name="action" type="hidden" value="r"/>
|
23 |
+
</form>
|
24 |
+
<div class="content-header">
|
25 |
+
<table cellspacing="0">
|
26 |
+
<tbody><tr>
|
27 |
+
<td style="width:50%;"><h3 class="icon-head head-promo-catalog">{dialogCaption}</h3></td>
|
28 |
+
</tr>
|
29 |
+
</tbody>
|
30 |
+
</table>
|
31 |
+
</div>
|
32 |
+
<div class="entry-edit">
|
33 |
+
<div class="entry-edit-head"><h4>{sectionCaption}</h4></div>
|
34 |
+
<fieldset>
|
35 |
+
<table cellspacing="0" class="form-list">
|
36 |
+
<tbody>
|
37 |
+
<tr>
|
38 |
+
<td>{installingText}</td>
|
39 |
+
</tr>
|
40 |
+
<tr>
|
41 |
+
<td>{confEmailText}</td>
|
42 |
+
</tr>
|
43 |
+
<tr>
|
44 |
+
<td ></td>
|
45 |
+
</tr>
|
46 |
+
<tr>
|
47 |
+
<td><div name="liveagent_wait_status" id="liveagent_wait_status" style="padding:10px;">{installText}...</div></td>
|
48 |
+
</tr>
|
49 |
+
<tr>
|
50 |
+
<td></td>
|
51 |
+
</tr>
|
52 |
+
<tr>
|
53 |
+
<td><i>{bitLongerText}</i><a href="http://support.qualityunit.com/knowledgebase/live-agent/integration/magento-plugin/frequently-asked-questions.html" target="_blank">{bitLongerLink}</a></td>
|
54 |
+
</tr>
|
55 |
+
</tbody>
|
56 |
+
</table>
|
57 |
+
</fieldset>
|
58 |
+
</div>
|
59 |
+
<script type="text/javascript"><!--//--><![CDATA[//><!--
|
60 |
+
setTimeout("document.getElementById(\'liveagent_wait_status\').innerHTML = \'{initializingText}\'", 5);
|
61 |
+
var timer = 3000;
|
62 |
+
var percentage = 4;
|
63 |
+
for (i=0;i<24;i++) {
|
64 |
+
setTimeout("document.getElementById(\'liveagent_wait_status\').innerHTML = \'{installText} " + percentage + "% ...\'", timer);
|
65 |
+
timer+=1000;
|
66 |
+
percentage+=4;
|
67 |
+
}
|
68 |
+
setTimeout("window.location.reload()", timer);
|
69 |
+
//--><!]]></script>
|
70 |
+
';
|
71 |
+
}
|
72 |
+
}
|
app/code/local/Qualityunit/Liveagent/{Helper → _Helper}/.Auth.php.swp
RENAMED
File without changes
|
app/code/local/Qualityunit/Liveagent/_Helper/Account.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Qualityunit_Liveagent_Helper_Account extends Mage_Core_Helper_Abstract {
|
4 |
+
public static function isOnline() {
|
5 |
+
$auth = new Qualityunit_Liveagent_Helper_Auth();
|
6 |
+
try {
|
7 |
+
$auth->ping();
|
8 |
+
Mage::log('Account is online!', Zend_Log::INFO);
|
9 |
+
return true;
|
10 |
+
} catch (Qualityunit_Liveagent_Exception_ConnectProblem $e) {
|
11 |
+
Mage::log('Account not online', Zend_Log::INFO);
|
12 |
+
return false;
|
13 |
+
}
|
14 |
+
}
|
15 |
+
}
|
app/code/local/Qualityunit/Liveagent/_Helper/Auth.php
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @copyright Copyright (c) 2007 Quality Unit s.r.o.
|
4 |
+
* @author Juraj Simon
|
5 |
+
* @package WpLiveAgentPlugin
|
6 |
+
* @version 1.0.0
|
7 |
+
*
|
8 |
+
* Licensed under GPL2
|
9 |
+
*/
|
10 |
+
|
11 |
+
class Qualityunit_Liveagent_Helper_Auth extends Qualityunit_Liveagent_Helper_Base {
|
12 |
+
public function ping($url = null) {
|
13 |
+
$url = $this->getRemoteApiUrl($url);
|
14 |
+
$request = new La_Rpc_DataRequest("Gpf_Common_ConnectionUtil", "ping");
|
15 |
+
$request->setUrl($url);
|
16 |
+
try {
|
17 |
+
$request->sendNow();
|
18 |
+
} catch (Exception $e) {
|
19 |
+
$this->_log('Unable to ping Live Agent remotelly' . $e->getMessage());
|
20 |
+
throw new Qualityunit_Liveagent_Exception_ConnectProblem($e->getMessage());
|
21 |
+
}
|
22 |
+
$data = $request->getData();
|
23 |
+
if ($data->getParam('status') != 'OK') {
|
24 |
+
throw new Qualityunit_Liveagent_Exception_ConnectProblem($e->getMessage());
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
public function getauthTokenByApi($url, $apiKey, $ownerEmail) {
|
29 |
+
$url = $this->getRemoteApiUrl($url);
|
30 |
+
$url .= '?handler=agents/' . urlencode($ownerEmail) . '&apikey=' . $apiKey;
|
31 |
+
|
32 |
+
$ch = curl_init();
|
33 |
+
curl_setopt($ch,CURLOPT_URL, $url);
|
34 |
+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
|
35 |
+
$this->_log('Fetching user auth info from api url: ' . $url);
|
36 |
+
$curl_response=curl_exec($ch);
|
37 |
+
if ($curl_response === false) {
|
38 |
+
$info = curl_getinfo($ch);
|
39 |
+
curl_close($ch);
|
40 |
+
$this->_log('Error calling API request: ' . var_export($info, true));
|
41 |
+
return '';
|
42 |
+
}
|
43 |
+
$info = curl_getinfo($ch);
|
44 |
+
curl_close($ch);
|
45 |
+
$decodedResponse = json_decode($curl_response);
|
46 |
+
if (!isset($decodedResponse->response)) {
|
47 |
+
$this->_log('Error decoding API response: ' . $curl_response . ', info: ' . var_export($info, true));
|
48 |
+
return '';
|
49 |
+
}
|
50 |
+
if ($info['http_code'] != 200) {
|
51 |
+
$this->_log('API response returned error: ' . $curl_response . ', info: ' . var_export($info, true));
|
52 |
+
return '';
|
53 |
+
}
|
54 |
+
return $decodedResponse->response->authtoken;
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* @return La_Rpc_Data
|
59 |
+
*/
|
60 |
+
public function LoginAndGetLoginData($url = null, $username = null, $password = null) {
|
61 |
+
$url = $this->getRemoteApiUrl($url);
|
62 |
+
|
63 |
+
$request = new La_Rpc_DataRequest("Gpf_Api_AuthService", "authenticate");
|
64 |
+
|
65 |
+
if ($username == null) {
|
66 |
+
$request->setField('username' ,$this->settingsModel->getOwnerEmail());
|
67 |
+
} else {
|
68 |
+
$request->setField('username' ,$username);
|
69 |
+
}
|
70 |
+
|
71 |
+
if ($password == null) {
|
72 |
+
$request->setField('password' ,$this->settingsModel->getOwnerPassword());
|
73 |
+
} else {
|
74 |
+
$request->setField('password' ,$password);
|
75 |
+
}
|
76 |
+
$request->setUrl($url);
|
77 |
+
try {
|
78 |
+
$request->sendNow();
|
79 |
+
} catch (Exception $e) {
|
80 |
+
$this->_log('Unable to login.');
|
81 |
+
//$this->_log($e->getMessage());
|
82 |
+
throw new Qualityunit_Liveagent_Exception_ConnectProblem();
|
83 |
+
}
|
84 |
+
if ($request->getData()->getParam('error')!=null) {
|
85 |
+
$this->_log('Answer from server: ' . print_r($request->getResponseObject()->toObject(), true));
|
86 |
+
throw new Qualityunit_Liveagent_Exception_ConnectProblem();
|
87 |
+
}
|
88 |
+
return $request->getData();
|
89 |
+
}
|
90 |
+
}
|
app/code/local/Qualityunit/Liveagent/_Helper/Base.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @copyright Copyright (c) 2007 Quality Unit s.r.o.
|
4 |
+
* @author Juraj Simon
|
5 |
+
* @package WpLiveAgentPlugin
|
6 |
+
* @version 1.0.0
|
7 |
+
*
|
8 |
+
* Licensed under GPL2
|
9 |
+
*/
|
10 |
+
|
11 |
+
class Qualityunit_Liveagent_Helper_Base {
|
12 |
+
/**
|
13 |
+
* @var Qualityunit_Liveagent_Helper_Settings
|
14 |
+
*/
|
15 |
+
protected $settingsModel;
|
16 |
+
const ACCOUNT_STATUS_NOTSET = 'N';
|
17 |
+
const ACCOUNT_STATUS_SET = 'S';
|
18 |
+
const ACCOUNT_STATUS_WAIT = 'W';
|
19 |
+
|
20 |
+
public function _log($message) {
|
21 |
+
Mage::log($message, Zend_Log::DEBUG);
|
22 |
+
}
|
23 |
+
|
24 |
+
public function __construct() {
|
25 |
+
$this->settingsModel = new Qualityunit_Liveagent_Helper_Settings();
|
26 |
+
}
|
27 |
+
|
28 |
+
public function showAdminError($error) {
|
29 |
+
Mage::log($message, Zend_Log::ERR);
|
30 |
+
}
|
31 |
+
|
32 |
+
public function showConnectionError() {
|
33 |
+
$this->showAdminError(Mage::helper('liveagent')->__('Unable to connect to Live Agent. please check your connection settings'));
|
34 |
+
}
|
35 |
+
|
36 |
+
public function getRemoteTrackJsUrl() {
|
37 |
+
return $this->settingsModel->getOption(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME) . '/scripts/trackjs.php';
|
38 |
+
}
|
39 |
+
|
40 |
+
public function getRemotePixUrl() {
|
41 |
+
return $this->settingsModel->getOption(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME) . '/scripts/pix.gif';
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getRemoteApiUrl($url = null) {
|
45 |
+
if ($url == null) {
|
46 |
+
return $this->settingsModel->getOption(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME) . '/api/index.php';
|
47 |
+
} else {
|
48 |
+
return $url . '/api/index.php';
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
protected function isEmpty($var) {
|
53 |
+
return $var=== null || $var=='';
|
54 |
+
}
|
55 |
+
}
|
56 |
+
?>
|
app/code/local/Qualityunit/Liveagent/_Helper/Data.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Qualityunit_Liveagent_Helper_Data extends Mage_Core_Helper_Abstract {
|
4 |
+
public static function convertOldButton() {
|
5 |
+
$settings = new Qualityunit_Liveagent_Helper_Settings();
|
6 |
+
$setting = $settings->getOption(Qualityunit_Liveagent_Helper_Settings::BUTTON_CODE);
|
7 |
+
if ($setting != '') {
|
8 |
+
return;
|
9 |
+
}
|
10 |
+
$collection = Mage::getModel('liveagent/buttons')->getCollection();
|
11 |
+
$buttonId = null;
|
12 |
+
foreach ($collection as $button) {
|
13 |
+
if ($buttonId === null && $button->getOnlinestatus() == 'Y' && $button->getContenttype() == 'F') {
|
14 |
+
$buttonId = $button->getButtonid();
|
15 |
+
}
|
16 |
+
$button->delete();
|
17 |
+
}
|
18 |
+
if ($buttonId == null) {
|
19 |
+
return;
|
20 |
+
}
|
21 |
+
$settings->saveButtonCodeForButtonId($buttonId);
|
22 |
+
}
|
23 |
+
}
|
app/code/local/Qualityunit/Liveagent/_Helper/PhpApi.php
ADDED
@@ -0,0 +1,4303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @copyright Copyright (c) 2010-2011 Quality Unit s.r.o.
|
4 |
+
* @author Quality Unit
|
5 |
+
* @package PhpApi
|
6 |
+
*
|
7 |
+
* Licensed under the Quality Unit, s.r.o. Dual License Agreement,
|
8 |
+
* Version 1.0 (the "License"); you may not use this file except in compliance
|
9 |
+
* with the License. You may obtain a copy of the License at
|
10 |
+
* http://www.qualityunit.com/licenses/gpf
|
11 |
+
* Generated on: 2011-06-06 04:17:42
|
12 |
+
* Framework version: 1.5.22
|
13 |
+
*
|
14 |
+
*/
|
15 |
+
|
16 |
+
if (!class_exists('La_Lang', false)) {
|
17 |
+
class La_Lang {
|
18 |
+
public static function _replaceArgs($message, $args = null) {
|
19 |
+
if (!is_array($args)) {
|
20 |
+
$args = func_get_args();
|
21 |
+
}
|
22 |
+
if(count($args) > 1 && substr_count($message, '%s') < count($args)) {
|
23 |
+
array_shift($args);
|
24 |
+
return vsprintf($message, $args);
|
25 |
+
}
|
26 |
+
return $message;
|
27 |
+
}
|
28 |
+
|
29 |
+
public static function _($message, $args = null, $langCode = '') {
|
30 |
+
if (!is_array($args)) {
|
31 |
+
$args = func_get_args();
|
32 |
+
}
|
33 |
+
return self::_replaceArgs($message, $args);
|
34 |
+
}
|
35 |
+
|
36 |
+
public static function _sys($message, $args = null) {
|
37 |
+
if (!is_array($args)) {
|
38 |
+
$args = func_get_args();
|
39 |
+
}
|
40 |
+
return self::_replaceArgs($message, $args);
|
41 |
+
}
|
42 |
+
|
43 |
+
public static function _runtime($message) {
|
44 |
+
return $message;
|
45 |
+
}
|
46 |
+
|
47 |
+
public static function _localizeRuntime($message, $langCode = '') {
|
48 |
+
preg_match_all('/##(.+?)##/ms', $message, $attributes, PREG_OFFSET_CAPTURE);
|
49 |
+
foreach ($attributes[1] as $index => $attribute) {
|
50 |
+
$message = str_replace($attributes[0][$index][0], self::_($attribute[0], null, $langCode), $message);
|
51 |
+
}
|
52 |
+
return $message;
|
53 |
+
|
54 |
+
}
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
if (!class_exists('La_Object', false)) {
|
59 |
+
class La_Object {
|
60 |
+
/**
|
61 |
+
* Translate input message into selected language.
|
62 |
+
* If translation will not be found, return same message.
|
63 |
+
*
|
64 |
+
* @param string $message
|
65 |
+
* @return string
|
66 |
+
*/
|
67 |
+
public function _($message) {
|
68 |
+
$args = func_get_args();
|
69 |
+
return La_Lang::_($message, $args);
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Translates text enclosed in ##any text##
|
74 |
+
* This function is not parsed by language parser, because as input should be used e.g. texts loaded from database
|
75 |
+
*
|
76 |
+
* @param string $message String to translate
|
77 |
+
* @return string Translated text
|
78 |
+
*/
|
79 |
+
public function _localize($message) {
|
80 |
+
return La_Lang::_localizeRuntime($message);
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Translate input message into default language defined in language settings for account.
|
85 |
+
* This function should be used in case message should be translated to default language (e.g. log messages written to event log)
|
86 |
+
*
|
87 |
+
* @param string $message
|
88 |
+
* @return string
|
89 |
+
*/
|
90 |
+
public function _sys($message) {
|
91 |
+
$args = func_get_args();
|
92 |
+
return La_Lang::_sys($message, $args);
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
} //end La_Object
|
97 |
+
|
98 |
+
if (!interface_exists('La_Controller', false)) {
|
99 |
+
interface La_Controller {
|
100 |
+
/**
|
101 |
+
* @throws La_Controller_Exception_UnsupportedRequest
|
102 |
+
*/
|
103 |
+
public function execute();
|
104 |
+
}
|
105 |
+
|
106 |
+
} //end La_Controller
|
107 |
+
|
108 |
+
if (!interface_exists('La_Rpc_Serializable', false)) {
|
109 |
+
interface La_Rpc_Serializable {
|
110 |
+
|
111 |
+
public function toObject();
|
112 |
+
|
113 |
+
public function toText();
|
114 |
+
}
|
115 |
+
|
116 |
+
} //end La_Rpc_Serializable
|
117 |
+
|
118 |
+
if (!interface_exists('La_Rpc_DataEncoder', false)) {
|
119 |
+
interface La_Rpc_DataEncoder {
|
120 |
+
function encodeResponse(La_Rpc_Serializable $response);
|
121 |
+
}
|
122 |
+
|
123 |
+
|
124 |
+
|
125 |
+
} //end La_Rpc_DataEncoder
|
126 |
+
|
127 |
+
if (!interface_exists('La_Rpc_DataDecoder', false)) {
|
128 |
+
interface La_Rpc_DataDecoder {
|
129 |
+
/**
|
130 |
+
* @param string $str
|
131 |
+
* @return StdClass
|
132 |
+
*/
|
133 |
+
function decode($str);
|
134 |
+
}
|
135 |
+
|
136 |
+
|
137 |
+
|
138 |
+
} //end La_Rpc_DataDecoder
|
139 |
+
|
140 |
+
if (!class_exists('La_Rpc_Array', false)) {
|
141 |
+
class La_Rpc_Array extends La_Object implements La_Rpc_Serializable, IteratorAggregate {
|
142 |
+
|
143 |
+
private $array;
|
144 |
+
|
145 |
+
function __construct(array $array = null){
|
146 |
+
if($array === null){
|
147 |
+
$this->array = array();
|
148 |
+
}else{
|
149 |
+
$this->array = $array;
|
150 |
+
}
|
151 |
+
}
|
152 |
+
|
153 |
+
public function add($response) {
|
154 |
+
if(is_scalar($response) || $response instanceof La_Rpc_Serializable) {
|
155 |
+
$this->array[] = $response;
|
156 |
+
return;
|
157 |
+
}
|
158 |
+
throw new La_Exception("Value of type " . gettype($response) . " is not scalar or La_Rpc_Serializable");
|
159 |
+
}
|
160 |
+
|
161 |
+
public function toObject() {
|
162 |
+
$array = array();
|
163 |
+
foreach ($this->array as $response) {
|
164 |
+
if($response instanceof La_Rpc_Serializable) {
|
165 |
+
$array[] = $response->toObject();
|
166 |
+
} else {
|
167 |
+
$array[] = $response;
|
168 |
+
}
|
169 |
+
}
|
170 |
+
return $array;
|
171 |
+
}
|
172 |
+
|
173 |
+
public function toText() {
|
174 |
+
return var_dump($this->array);
|
175 |
+
}
|
176 |
+
|
177 |
+
public function getCount() {
|
178 |
+
return count($this->array);
|
179 |
+
}
|
180 |
+
|
181 |
+
public function get($index) {
|
182 |
+
return $this->array[$index];
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
*
|
187 |
+
* @return ArrayIterator
|
188 |
+
*/
|
189 |
+
public function getIterator() {
|
190 |
+
return new ArrayIterator($this->array);
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
} //end La_Rpc_Array
|
195 |
+
|
196 |
+
if (!class_exists('La_Rpc_Server', false)) {
|
197 |
+
class La_Rpc_Server extends La_Object implements La_Controller {
|
198 |
+
const REQUESTS = 'R';
|
199 |
+
const RUN_METHOD = 'run';
|
200 |
+
const FORM_REQUEST = 'FormRequest';
|
201 |
+
const FORM_RESPONSE = 'FormResponse';
|
202 |
+
const BODY_DATA_NAME = 'D';
|
203 |
+
|
204 |
+
|
205 |
+
const HANDLER_FORM = 'Y';
|
206 |
+
const HANDLER_JASON = 'N';
|
207 |
+
const HANDLER_WINDOW_NAME = 'W';
|
208 |
+
|
209 |
+
/**
|
210 |
+
* @var La_Rpc_DataEncoder
|
211 |
+
*/
|
212 |
+
private $dataEncoder;
|
213 |
+
/**
|
214 |
+
* @var La_Rpc_DataDecoder
|
215 |
+
*/
|
216 |
+
private $dataDecoder;
|
217 |
+
|
218 |
+
public function __construct() {
|
219 |
+
}
|
220 |
+
|
221 |
+
private function initDatabaseLogger() {
|
222 |
+
$logger = La_Log_Logger::getInstance();
|
223 |
+
|
224 |
+
if(!$logger->checkLoggerTypeExists(La_Log_LoggerDatabase::TYPE)) {
|
225 |
+
$logger->setGroup(La_Common_String::generateId(10));
|
226 |
+
$logLevel = La_Settings::get(La_Settings_Gpf::LOG_LEVEL_SETTING_NAME);
|
227 |
+
$logger->add(La_Log_LoggerDatabase::TYPE, $logLevel);
|
228 |
+
}
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Return response to standard output
|
233 |
+
*/
|
234 |
+
public function execute($request = '') {
|
235 |
+
$response = $this->encodeResponse($this->executeRequest($request));
|
236 |
+
La_Http::output($response);
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* @return La_Rpc_Serializable
|
241 |
+
*/
|
242 |
+
public function executeRequest($request = '') {
|
243 |
+
try {
|
244 |
+
if(isset($_REQUEST[self::BODY_DATA_NAME])) {
|
245 |
+
$request = $this->parseRequestDataFromPost($_REQUEST[self::BODY_DATA_NAME]);
|
246 |
+
}
|
247 |
+
if($this->isStandardRequestUsed($_REQUEST)) {
|
248 |
+
$request = $this->setStandardRequest();
|
249 |
+
}
|
250 |
+
|
251 |
+
$this->setDecoder($request);
|
252 |
+
$params = new La_Rpc_Params($this->decodeRequest($request));
|
253 |
+
if ($params->getClass() == '' || $params->getMethod() == '') {
|
254 |
+
throw new La_Controller_Exception_UnsupportedRequest();
|
255 |
+
}
|
256 |
+
$this->setEncoder($params);
|
257 |
+
$response = $this->executeRequestParams($params);
|
258 |
+
} catch (La_Controller_Exception_UnsupportedRequest $e) {
|
259 |
+
throw $e;
|
260 |
+
} catch (Exception $e) {
|
261 |
+
return new La_Rpc_ExceptionResponse($e);
|
262 |
+
}
|
263 |
+
return $response;
|
264 |
+
}
|
265 |
+
|
266 |
+
private function parseRequestDataFromPost($data) {
|
267 |
+
if(get_magic_quotes_gpc()) {
|
268 |
+
return stripslashes($data);
|
269 |
+
}
|
270 |
+
return $data;
|
271 |
+
}
|
272 |
+
|
273 |
+
/**
|
274 |
+
*
|
275 |
+
* @param unknown_type $requestObj
|
276 |
+
* @return La_Rpc_Serializable
|
277 |
+
*/
|
278 |
+
private function executeRequestParams(La_Rpc_Params $params) {
|
279 |
+
if (La_Application::getInstance()->isInMaintenanceMode()
|
280 |
+
&& !La_Paths::getInstance()->isInstallModeActive()) {
|
281 |
+
return new La_Rpc_MaintenenceModeResponse();
|
282 |
+
}
|
283 |
+
try {
|
284 |
+
La_Db_LoginHistory::logRequest();
|
285 |
+
return $this->callServiceMethod($params);
|
286 |
+
} catch (La_Session_Exception_SessionExpired $e) {
|
287 |
+
return new La_Rpc_SessionExpiredResponse($e);
|
288 |
+
} catch (Exception $e) {
|
289 |
+
return new La_Rpc_ExceptionResponse($e);
|
290 |
+
}
|
291 |
+
}
|
292 |
+
|
293 |
+
/**
|
294 |
+
* @throws La_Session_Exception_SessionExpired
|
295 |
+
*/
|
296 |
+
protected function callServiceMethod(La_Rpc_Params $params) {
|
297 |
+
$method = new La_Rpc_ServiceMethod($params);
|
298 |
+
return $method->invoke($params);
|
299 |
+
}
|
300 |
+
|
301 |
+
/**
|
302 |
+
* Compute correct handler type for server response
|
303 |
+
*
|
304 |
+
* @param array $requestData
|
305 |
+
* @param string $type
|
306 |
+
* @return string
|
307 |
+
*/
|
308 |
+
private function getEncoderHandlerType($requestData) {
|
309 |
+
if ($this->isFormHandler($requestData, self::FORM_RESPONSE, self::HANDLER_FORM)) {
|
310 |
+
return self::HANDLER_FORM;
|
311 |
+
}
|
312 |
+
if ($this->isFormHandler($requestData, self::FORM_RESPONSE, self::HANDLER_WINDOW_NAME)) {
|
313 |
+
return self::HANDLER_WINDOW_NAME;
|
314 |
+
}
|
315 |
+
return self::HANDLER_JASON;
|
316 |
+
}
|
317 |
+
|
318 |
+
|
319 |
+
private function isFormHandler($requestData, $type, $handler) {
|
320 |
+
return (isset($_REQUEST[$type]) && $_REQUEST[$type] == $handler) ||
|
321 |
+
(isset($requestData) && isset($requestData[$type]) && $requestData[$type] == $handler);
|
322 |
+
}
|
323 |
+
|
324 |
+
private function decodeRequest($requestData) {
|
325 |
+
return $this->dataDecoder->decode($requestData);
|
326 |
+
}
|
327 |
+
|
328 |
+
private function isStandardRequestUsed($requestArray) {
|
329 |
+
return is_array($requestArray) && array_key_exists(La_Rpc_Params::CLASS_NAME, $requestArray);
|
330 |
+
}
|
331 |
+
|
332 |
+
private function setStandardRequest() {
|
333 |
+
return array_merge($_POST, $_GET);
|
334 |
+
}
|
335 |
+
|
336 |
+
private function isFormRequest($request) {
|
337 |
+
return $this->isFormHandler($request, self::FORM_REQUEST, self::HANDLER_FORM);
|
338 |
+
}
|
339 |
+
|
340 |
+
private function encodeResponse(La_Rpc_Serializable $response) {
|
341 |
+
return $this->dataEncoder->encodeResponse($response);
|
342 |
+
}
|
343 |
+
|
344 |
+
|
345 |
+
private function setDecoder($request) {
|
346 |
+
if ($this->isFormRequest($request)) {
|
347 |
+
$this->dataDecoder = new La_Rpc_FormHandler();
|
348 |
+
} else {
|
349 |
+
$this->dataDecoder = new La_Rpc_Json();
|
350 |
+
}
|
351 |
+
}
|
352 |
+
|
353 |
+
private function setEncoder(La_Rpc_Params $params) {
|
354 |
+
switch ($params->get(self::FORM_RESPONSE)) {
|
355 |
+
case self::HANDLER_FORM:
|
356 |
+
$this->dataEncoder = new La_Rpc_FormHandler();
|
357 |
+
break;
|
358 |
+
case self::HANDLER_WINDOW_NAME:
|
359 |
+
$this->dataEncoder = new La_Rpc_WindowNameHandler();
|
360 |
+
break;
|
361 |
+
default:
|
362 |
+
$this->dataEncoder = new La_Rpc_Json();
|
363 |
+
break;
|
364 |
+
}
|
365 |
+
}
|
366 |
+
|
367 |
+
/**
|
368 |
+
* Executes multi request
|
369 |
+
*
|
370 |
+
* @service
|
371 |
+
* @anonym
|
372 |
+
* @return La_Rpc_Serializable
|
373 |
+
*/
|
374 |
+
public function run(La_Rpc_Params $params) {
|
375 |
+
$requestArray = $params->get(self::REQUESTS);
|
376 |
+
|
377 |
+
$response = new La_Rpc_Array();
|
378 |
+
foreach ($requestArray as $request) {
|
379 |
+
$response->add($this->executeRequestParams(new La_Rpc_Params($request)));
|
380 |
+
}
|
381 |
+
return $response;
|
382 |
+
}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Set time offset between client and server and store it to session
|
386 |
+
* Offset is computed as client time - server time
|
387 |
+
*
|
388 |
+
* @anonym
|
389 |
+
* @service
|
390 |
+
* @param La_Rpc_Params $params
|
391 |
+
* @return La_Rpc_Action
|
392 |
+
*/
|
393 |
+
public function syncTime(La_Rpc_Params $params) {
|
394 |
+
$action = new La_Rpc_Action($params);
|
395 |
+
La_Module::getProperties()->setTimeOffset($action->getParam('offset')/1000);
|
396 |
+
$action->addOk();
|
397 |
+
return $action;
|
398 |
+
}
|
399 |
+
}
|
400 |
+
|
401 |
+
} //end La_Rpc_Server
|
402 |
+
|
403 |
+
if (!class_exists('La_Rpc_MultiRequest', false)) {
|
404 |
+
class La_Rpc_MultiRequest extends La_Object {
|
405 |
+
private $url = '';
|
406 |
+
/**
|
407 |
+
*
|
408 |
+
* @var La_Rpc_Array
|
409 |
+
*/
|
410 |
+
private $requests;
|
411 |
+
/**
|
412 |
+
* @var La_Rpc_Json
|
413 |
+
*/
|
414 |
+
private $json;
|
415 |
+
protected $serverClassName = 'Gpf_Rpc_Server';
|
416 |
+
|
417 |
+
private $sessionId = null;
|
418 |
+
|
419 |
+
private $debugRequests = false;
|
420 |
+
|
421 |
+
/**
|
422 |
+
* @var La_Rpc_MultiRequest
|
423 |
+
*/
|
424 |
+
private static $instance;
|
425 |
+
|
426 |
+
public function __construct() {
|
427 |
+
$this->json = new La_Rpc_Json();
|
428 |
+
$this->requests = new La_Rpc_Array();
|
429 |
+
}
|
430 |
+
|
431 |
+
/**
|
432 |
+
* @return La_Rpc_MultiRequest
|
433 |
+
*/
|
434 |
+
public static function getInstance() {
|
435 |
+
if(self::$instance === null) {
|
436 |
+
self::$instance = new La_Rpc_MultiRequest();
|
437 |
+
}
|
438 |
+
return self::$instance;
|
439 |
+
}
|
440 |
+
|
441 |
+
public static function setInstance(La_Rpc_MultiRequest $instance) {
|
442 |
+
self::$instance = $instance;
|
443 |
+
}
|
444 |
+
|
445 |
+
public function add(La_Rpc_Request $request) {
|
446 |
+
$this->requests->add($request);
|
447 |
+
}
|
448 |
+
|
449 |
+
protected function sendRequest($requestBody) {
|
450 |
+
$request = new La_Net_Http_Request();
|
451 |
+
|
452 |
+
$request->setMethod('POST');
|
453 |
+
$request->setBody(La_Rpc_Server::BODY_DATA_NAME . '=' . urlencode($requestBody));
|
454 |
+
$request->setUrl($this->url);
|
455 |
+
|
456 |
+
$client = new La_Net_Http_Client();
|
457 |
+
$response = $client->execute($request);
|
458 |
+
return $response->getBody();
|
459 |
+
}
|
460 |
+
|
461 |
+
public function setSessionId($sessionId) {
|
462 |
+
$this->sessionId = $sessionId;
|
463 |
+
}
|
464 |
+
|
465 |
+
public function setDebugRequests($debug) {
|
466 |
+
$this->debugRequests = $debug;
|
467 |
+
}
|
468 |
+
|
469 |
+
public function send() {
|
470 |
+
$request = new La_Rpc_Request($this->serverClassName, La_Rpc_Server::RUN_METHOD);
|
471 |
+
$request->addParam(La_Rpc_Server::REQUESTS, $this->requests);
|
472 |
+
if($this->sessionId != null) {
|
473 |
+
$request->addParam("S", $this->sessionId);
|
474 |
+
}
|
475 |
+
$requestBody = $this->json->encodeResponse($request);
|
476 |
+
$responseText = $this->sendRequest($requestBody);
|
477 |
+
$responseArray = $this->json->decode($responseText);
|
478 |
+
if (!is_array($responseArray)) {
|
479 |
+
throw new La_Exception("Response decoding failed: not array. Received text: $responseText");
|
480 |
+
}
|
481 |
+
|
482 |
+
if (count($responseArray) != $this->requests->getCount()) {
|
483 |
+
throw new La_Exception("Response decoding failed: Number of responses is not same as number of requests");
|
484 |
+
}
|
485 |
+
|
486 |
+
$exception = false;
|
487 |
+
foreach ($responseArray as $index => $response) {
|
488 |
+
if (is_object($response) && isset($response->e)) {
|
489 |
+
$exception = true;
|
490 |
+
$this->requests->get($index)->setResponseError($response->e);
|
491 |
+
} else {
|
492 |
+
$this->requests->get($index)->setResponse($response);
|
493 |
+
}
|
494 |
+
}
|
495 |
+
if($exception) {
|
496 |
+
$messages = '';
|
497 |
+
foreach ($this->requests as $request) {
|
498 |
+
$messages .= $request->getResponseError() . "|";
|
499 |
+
}
|
500 |
+
}
|
501 |
+
$this->requests = new La_Rpc_Array();
|
502 |
+
if($exception) {
|
503 |
+
throw new La_Rpc_ExecutionException($messages);
|
504 |
+
}
|
505 |
+
}
|
506 |
+
|
507 |
+
public function setUrl($url) {
|
508 |
+
$this->url = $url;
|
509 |
+
}
|
510 |
+
|
511 |
+
public function getUrl() {
|
512 |
+
return $this->url;
|
513 |
+
}
|
514 |
+
|
515 |
+
private function getCookies() {
|
516 |
+
$cookiesString = '';
|
517 |
+
foreach ($_COOKIE as $name => $value) {
|
518 |
+
$cookiesString .= "$name=$value;";
|
519 |
+
}
|
520 |
+
return $cookiesString;
|
521 |
+
}
|
522 |
+
}
|
523 |
+
|
524 |
+
|
525 |
+
} //end La_Rpc_MultiRequest
|
526 |
+
|
527 |
+
if (!class_exists('La_Rpc_Params', false)) {
|
528 |
+
class La_Rpc_Params extends La_Object implements La_Rpc_Serializable {
|
529 |
+
private $params;
|
530 |
+
const CLASS_NAME = 'C';
|
531 |
+
const METHOD_NAME = 'M';
|
532 |
+
const SESSION_ID = 'S';
|
533 |
+
const ACCOUNT_ID = 'aid';
|
534 |
+
|
535 |
+
function __construct($params = null) {
|
536 |
+
if($params === null) {
|
537 |
+
$this->params = new stdClass();
|
538 |
+
return;
|
539 |
+
}
|
540 |
+
$this->params = $params;
|
541 |
+
}
|
542 |
+
|
543 |
+
public static function createGetRequest($className, $methodName = 'execute', $formRequest = false, $formResponse = false) {
|
544 |
+
$requestData = array();
|
545 |
+
$requestData[self::CLASS_NAME] = $className;
|
546 |
+
$requestData[self::METHOD_NAME] = $methodName;
|
547 |
+
$requestData[La_Rpc_Server::FORM_REQUEST] = $formRequest ? Gpf::YES : '';
|
548 |
+
$requestData[La_Rpc_Server::FORM_RESPONSE] = $formResponse ? Gpf::YES : '';
|
549 |
+
return $requestData;
|
550 |
+
}
|
551 |
+
|
552 |
+
/**
|
553 |
+
*
|
554 |
+
* @param unknown_type $className
|
555 |
+
* @param unknown_type $methodName
|
556 |
+
* @param unknown_type $formRequest
|
557 |
+
* @param unknown_type $formResponse
|
558 |
+
* @return La_Rpc_Params
|
559 |
+
*/
|
560 |
+
public static function create($className, $methodName = 'execute', $formRequest = false, $formResponse = false) {
|
561 |
+
$params = new La_Rpc_Params();
|
562 |
+
$obj = new stdClass();
|
563 |
+
foreach (self::createGetRequest($className, $methodName, $formRequest, $formResponse) as $name => $value) {
|
564 |
+
$params->add($name,$value);
|
565 |
+
}
|
566 |
+
return $params;
|
567 |
+
}
|
568 |
+
|
569 |
+
public function setArrayParams(array $params) {
|
570 |
+
foreach ($params as $name => $value) {
|
571 |
+
$this->add($name, $value);
|
572 |
+
}
|
573 |
+
}
|
574 |
+
|
575 |
+
public function exists($name) {
|
576 |
+
if(!is_object($this->params) || !array_key_exists($name, $this->params)) {
|
577 |
+
return false;
|
578 |
+
}
|
579 |
+
return true;
|
580 |
+
}
|
581 |
+
|
582 |
+
/**
|
583 |
+
*
|
584 |
+
* @param unknown_type $name
|
585 |
+
* @return mixed Return null if $name does not exist.
|
586 |
+
*/
|
587 |
+
public function get($name) {
|
588 |
+
if(!$this->exists($name)) {
|
589 |
+
return null;
|
590 |
+
}
|
591 |
+
return $this->params->{$name};
|
592 |
+
}
|
593 |
+
|
594 |
+
public function set($name, $value) {
|
595 |
+
if(!$this->exists($name)) {
|
596 |
+
return;
|
597 |
+
}
|
598 |
+
$this->params->{$name} = $value;
|
599 |
+
}
|
600 |
+
|
601 |
+
public function add($name, $value) {
|
602 |
+
$this->params->{$name} = $value;
|
603 |
+
}
|
604 |
+
|
605 |
+
public function getClass() {
|
606 |
+
return $this->get(self::CLASS_NAME);
|
607 |
+
}
|
608 |
+
|
609 |
+
public function getMethod() {
|
610 |
+
return $this->get(self::METHOD_NAME);
|
611 |
+
}
|
612 |
+
|
613 |
+
public function getSessionId() {
|
614 |
+
return $this->get(self::SESSION_ID);
|
615 |
+
}
|
616 |
+
|
617 |
+
public function clearSessionId() {
|
618 |
+
$this->set(self::SESSION_ID, null);
|
619 |
+
}
|
620 |
+
|
621 |
+
public function getAccountId() {
|
622 |
+
return $this->get(self::ACCOUNT_ID);
|
623 |
+
}
|
624 |
+
|
625 |
+
public function toObject() {
|
626 |
+
return $this->params;
|
627 |
+
}
|
628 |
+
|
629 |
+
public function toText() {
|
630 |
+
throw new La_Exception("Unimplemented");
|
631 |
+
}
|
632 |
+
}
|
633 |
+
|
634 |
+
|
635 |
+
} //end La_Rpc_Params
|
636 |
+
|
637 |
+
if (!class_exists('La_Exception', false)) {
|
638 |
+
class La_Exception extends Exception {
|
639 |
+
|
640 |
+
private $id;
|
641 |
+
|
642 |
+
public function __construct($message = '',$code = null) {
|
643 |
+
$trace = '';
|
644 |
+
foreach (debug_backtrace(false) as $i => $traceStep) {
|
645 |
+
$trace .= sprintf("#%s - %s::%s() at line %s<br>\n", $i, @$traceStep['class'], @$traceStep['function'], @$traceStep['line']);
|
646 |
+
}
|
647 |
+
$message .= "<br>\nTRACE:<br>\n" . $trace;
|
648 |
+
parent::__construct($message, $code);
|
649 |
+
}
|
650 |
+
|
651 |
+
protected function logException() {
|
652 |
+
La_Log::error($this->getMessage());
|
653 |
+
}
|
654 |
+
|
655 |
+
public function setId($id) {
|
656 |
+
$this->id = $id;
|
657 |
+
}
|
658 |
+
|
659 |
+
public function getId() {
|
660 |
+
return $this->id;
|
661 |
+
}
|
662 |
+
|
663 |
+
}
|
664 |
+
|
665 |
+
} //end La_Exception
|
666 |
+
|
667 |
+
if (!class_exists('La_Data_RecordSetNoRowException', false)) {
|
668 |
+
class La_Data_RecordSetNoRowException extends La_Exception {
|
669 |
+
public function __construct($keyValue) {
|
670 |
+
parent::__construct("'Row $keyValue does not exist");
|
671 |
+
}
|
672 |
+
|
673 |
+
protected function logException() {
|
674 |
+
}
|
675 |
+
}
|
676 |
+
|
677 |
+
} //end La_Data_RecordSetNoRowException
|
678 |
+
|
679 |
+
if (!class_exists('La_Rpc_ExecutionException', false)) {
|
680 |
+
class La_Rpc_ExecutionException extends La_Exception {
|
681 |
+
|
682 |
+
function __construct($message) {
|
683 |
+
parent::__construct('RPC Execution exception: ' . $message);
|
684 |
+
}
|
685 |
+
}
|
686 |
+
|
687 |
+
} //end La_Rpc_ExecutionException
|
688 |
+
|
689 |
+
if (!class_exists('La_Rpc_Object', false)) {
|
690 |
+
class La_Rpc_Object extends La_Object implements La_Rpc_Serializable {
|
691 |
+
|
692 |
+
private $object;
|
693 |
+
|
694 |
+
public function __construct($object = null) {
|
695 |
+
$this->object = $object;
|
696 |
+
}
|
697 |
+
|
698 |
+
public function toObject() {
|
699 |
+
if ($this->object != null) {
|
700 |
+
return $this->object;
|
701 |
+
}
|
702 |
+
return $this;
|
703 |
+
}
|
704 |
+
|
705 |
+
public function toText() {
|
706 |
+
return var_dump($this);
|
707 |
+
}
|
708 |
+
}
|
709 |
+
|
710 |
+
|
711 |
+
} //end La_Rpc_Object
|
712 |
+
|
713 |
+
if (!class_exists('La_Rpc_Request', false)) {
|
714 |
+
class La_Rpc_Request extends La_Object implements La_Rpc_Serializable {
|
715 |
+
protected $className;
|
716 |
+
protected $methodName;
|
717 |
+
private $responseError;
|
718 |
+
protected $response;
|
719 |
+
protected $apiSessionObject = null;
|
720 |
+
|
721 |
+
/**
|
722 |
+
* @var La_Rpc_MultiRequest
|
723 |
+
*/
|
724 |
+
private $multiRequest;
|
725 |
+
|
726 |
+
/**
|
727 |
+
* @var La_Rpc_Params
|
728 |
+
*/
|
729 |
+
protected $params;
|
730 |
+
private $accountId = null;
|
731 |
+
|
732 |
+
public function __construct($className, $methodName, La_Api_Session $apiSessionObject = null) {
|
733 |
+
$this->className = $className;
|
734 |
+
$this->methodName = $methodName;
|
735 |
+
$this->params = new La_Rpc_Params();
|
736 |
+
$this->setRequiredParams($this->className, $this->methodName);
|
737 |
+
if($apiSessionObject != null) {
|
738 |
+
$this->apiSessionObject = $apiSessionObject;
|
739 |
+
}
|
740 |
+
}
|
741 |
+
|
742 |
+
public function setAccountId($accountId) {
|
743 |
+
$this->accountId = $accountId;
|
744 |
+
}
|
745 |
+
|
746 |
+
public function addParam($name, $value) {
|
747 |
+
if(is_scalar($value) || is_null($value)) {
|
748 |
+
$this->params->add($name, $value);
|
749 |
+
return;
|
750 |
+
}
|
751 |
+
if($value instanceof La_Rpc_Serializable) {
|
752 |
+
$this->params->add($name, $value->toObject());
|
753 |
+
return;
|
754 |
+
}
|
755 |
+
throw new La_Exception("Cannot add request param: Value ($name=$value) is not scalar or La_Rpc_Serializable");
|
756 |
+
}
|
757 |
+
|
758 |
+
/**
|
759 |
+
*
|
760 |
+
* @return La_Rpc_MultiRequest
|
761 |
+
*/
|
762 |
+
private function getMultiRequest() {
|
763 |
+
if($this->multiRequest === null) {
|
764 |
+
return La_Rpc_MultiRequest::getInstance();
|
765 |
+
}
|
766 |
+
return $this->multiRequest;
|
767 |
+
}
|
768 |
+
|
769 |
+
public function setUrl($url) {
|
770 |
+
$this->multiRequest = new La_Rpc_MultiRequest();
|
771 |
+
$this->multiRequest->setUrl($url);
|
772 |
+
}
|
773 |
+
|
774 |
+
public function send() {
|
775 |
+
if($this->apiSessionObject != null) {
|
776 |
+
$this->multiRequest = new La_Rpc_MultiRequest();
|
777 |
+
$this->multiRequest->setUrl($this->apiSessionObject->getUrl());
|
778 |
+
$this->multiRequest->setSessionId($this->apiSessionObject->getSessionId());
|
779 |
+
$this->multiRequest->setDebugRequests($this->apiSessionObject->getDebug());
|
780 |
+
}
|
781 |
+
|
782 |
+
$multiRequest = $this->getMultiRequest();
|
783 |
+
$multiRequest->add($this);
|
784 |
+
}
|
785 |
+
|
786 |
+
public function sendNow() {
|
787 |
+
$this->send();
|
788 |
+
$this->getMultiRequest()->send();
|
789 |
+
}
|
790 |
+
|
791 |
+
public function setResponseError($message) {
|
792 |
+
$this->responseError = $message;
|
793 |
+
}
|
794 |
+
|
795 |
+
public function getResponseError() {
|
796 |
+
return $this->responseError;
|
797 |
+
}
|
798 |
+
|
799 |
+
public function setResponse($response) {
|
800 |
+
$this->response = $response;
|
801 |
+
}
|
802 |
+
|
803 |
+
public function toObject() {
|
804 |
+
return $this->params->toObject();
|
805 |
+
}
|
806 |
+
|
807 |
+
public function toText() {
|
808 |
+
throw new La_Exception("Unimplemented");
|
809 |
+
}
|
810 |
+
|
811 |
+
/**
|
812 |
+
*
|
813 |
+
* @return stdClass
|
814 |
+
*/
|
815 |
+
final public function getStdResponse() {
|
816 |
+
if(isset($this->responseError)) {
|
817 |
+
throw new La_Rpc_ExecutionException($this->responseError);
|
818 |
+
}
|
819 |
+
if($this->response === null) {
|
820 |
+
throw new La_Exception("Request not executed yet.");
|
821 |
+
}
|
822 |
+
return $this->response;
|
823 |
+
}
|
824 |
+
|
825 |
+
final public function getResponseObject() {
|
826 |
+
return new La_Rpc_Object($this->getStdResponse());
|
827 |
+
}
|
828 |
+
|
829 |
+
private function setRequiredParams($className, $methodName) {
|
830 |
+
$this->addParam(La_Rpc_Params::CLASS_NAME, $className);
|
831 |
+
$this->addParam(La_Rpc_Params::METHOD_NAME, $methodName);
|
832 |
+
}
|
833 |
+
|
834 |
+
/**
|
835 |
+
* @param La_Rpc_Params $params
|
836 |
+
*/
|
837 |
+
public function setParams(La_Rpc_Params $params) {
|
838 |
+
$originalParams = $this->params;
|
839 |
+
$this->params = $params;
|
840 |
+
$this->setRequiredParams($originalParams->getClass(), $originalParams->getMethod());
|
841 |
+
}
|
842 |
+
}
|
843 |
+
|
844 |
+
|
845 |
+
} //end La_Rpc_Request
|
846 |
+
|
847 |
+
if (!interface_exists('La_HttpResponse', false)) {
|
848 |
+
interface La_HttpResponse {
|
849 |
+
public function setCookieValue($name, $value = null, $expire = null, $path = null, $domain = null, $secure = null, $httpOnly = null);
|
850 |
+
|
851 |
+
public function setHeaderValue($name, $value, $replace = true, $httpResponseCode = null);
|
852 |
+
|
853 |
+
public function outputText($text);
|
854 |
+
}
|
855 |
+
|
856 |
+
} //end La_HttpResponse
|
857 |
+
|
858 |
+
if (!class_exists('La_Http', false)) {
|
859 |
+
class La_Http extends La_Object implements La_HttpResponse {
|
860 |
+
/**
|
861 |
+
*
|
862 |
+
* @var La_HttpResponse
|
863 |
+
*/
|
864 |
+
private static $instance = null;
|
865 |
+
|
866 |
+
/**
|
867 |
+
* @return La_Http
|
868 |
+
*/
|
869 |
+
private static function getInstance() {
|
870 |
+
if(self::$instance === null) {
|
871 |
+
self::$instance = new La_Http();
|
872 |
+
}
|
873 |
+
return self::$instance;
|
874 |
+
}
|
875 |
+
|
876 |
+
public static function setInstance(La_HttpResponse $instance) {
|
877 |
+
self::$instance = $instance;
|
878 |
+
}
|
879 |
+
|
880 |
+
public static function setCookie($name, $value = null, $expire = null, $path = null, $domain = null, $secure = null, $httpOnly = null) {
|
881 |
+
self::getInstance()->setCookieValue($name, $value, $expire, $path, $domain, $secure, $httpOnly);
|
882 |
+
}
|
883 |
+
|
884 |
+
public static function setHeader($name, $value, $httpResponseCode = null) {
|
885 |
+
self::getInstance()->setHeaderValue($name, $value, true, $httpResponseCode);
|
886 |
+
}
|
887 |
+
|
888 |
+
public static function output($text) {
|
889 |
+
self::getInstance()->outputText($text);
|
890 |
+
}
|
891 |
+
|
892 |
+
public function outputText($text) {
|
893 |
+
echo $text;
|
894 |
+
}
|
895 |
+
|
896 |
+
public function setHeaderValue($name, $value, $replace = true, $httpResponseCode = null) {
|
897 |
+
$fileName = '';
|
898 |
+
$line = '';
|
899 |
+
if(headers_sent($fileName, $line)) {
|
900 |
+
throw new La_Exception("Headers already sent in $fileName line $line while setting header $name: $value");
|
901 |
+
}
|
902 |
+
header($name . ': ' . $value, $replace, $httpResponseCode);
|
903 |
+
}
|
904 |
+
|
905 |
+
public function setCookieValue($name, $value = null, $expire = null, $path = null, $domain = null, $secure = null, $httpOnly = null) {
|
906 |
+
setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
|
907 |
+
}
|
908 |
+
|
909 |
+
public static function getCookie($name) {
|
910 |
+
if (!array_key_exists($name, $_COOKIE)) {
|
911 |
+
return null;
|
912 |
+
}
|
913 |
+
return $_COOKIE[$name];
|
914 |
+
}
|
915 |
+
|
916 |
+
public static function getRemoteIp() {
|
917 |
+
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
918 |
+
return $_SERVER['HTTP_X_FORWARDED_FOR'];
|
919 |
+
}
|
920 |
+
if (isset($_SERVER['REMOTE_ADDR'])) {
|
921 |
+
return $_SERVER['REMOTE_ADDR'];
|
922 |
+
}
|
923 |
+
return '';
|
924 |
+
}
|
925 |
+
|
926 |
+
public static function getRemoteHost(){
|
927 |
+
return @gethostbyaddr(self::getRemoteIp());
|
928 |
+
}
|
929 |
+
}
|
930 |
+
|
931 |
+
} //end La_Http
|
932 |
+
|
933 |
+
if (!interface_exists('La_Templates_HasAttributes', false)) {
|
934 |
+
interface La_Templates_HasAttributes {
|
935 |
+
function getAttributes();
|
936 |
+
}
|
937 |
+
|
938 |
+
} //end La_Templates_HasAttributes
|
939 |
+
|
940 |
+
if (!class_exists('La_Data_RecordHeader', false)) {
|
941 |
+
class La_Data_RecordHeader extends La_Object {
|
942 |
+
private $ids = array();
|
943 |
+
|
944 |
+
/**
|
945 |
+
* Create Record header object
|
946 |
+
*
|
947 |
+
* @param array $headerArray
|
948 |
+
*/
|
949 |
+
public function __construct($headerArray = null) {
|
950 |
+
if($headerArray === null) {
|
951 |
+
return;
|
952 |
+
}
|
953 |
+
|
954 |
+
foreach ($headerArray as $id) {
|
955 |
+
$this->add($id);
|
956 |
+
}
|
957 |
+
}
|
958 |
+
|
959 |
+
public function contains($id) {
|
960 |
+
return array_key_exists($id, $this->ids);
|
961 |
+
}
|
962 |
+
|
963 |
+
public function add($id) {
|
964 |
+
if($this->contains($id)) {
|
965 |
+
return;
|
966 |
+
}
|
967 |
+
|
968 |
+
$this->ids[$id] = count($this->ids);
|
969 |
+
}
|
970 |
+
|
971 |
+
public function getIds() {
|
972 |
+
return array_keys($this->ids);
|
973 |
+
}
|
974 |
+
|
975 |
+
public function getIndex($id) {
|
976 |
+
if(!$this->contains($id)) {
|
977 |
+
throw new La_Exception("Unknown column '" . $id ."'");
|
978 |
+
}
|
979 |
+
return $this->ids[$id];
|
980 |
+
}
|
981 |
+
|
982 |
+
public function getSize() {
|
983 |
+
return count($this->ids);
|
984 |
+
}
|
985 |
+
|
986 |
+
public function toArray() {
|
987 |
+
$response = array();
|
988 |
+
foreach ($this->ids as $columnId => $columnIndex) {
|
989 |
+
$response[] = $columnId;
|
990 |
+
}
|
991 |
+
return $response;
|
992 |
+
}
|
993 |
+
|
994 |
+
public function toObject() {
|
995 |
+
$result = array();
|
996 |
+
foreach ($this->ids as $columnId => $columnIndex) {
|
997 |
+
$result[] = $columnId;
|
998 |
+
}
|
999 |
+
return $result;
|
1000 |
+
}
|
1001 |
+
}
|
1002 |
+
|
1003 |
+
|
1004 |
+
} //end La_Data_RecordHeader
|
1005 |
+
|
1006 |
+
if (!interface_exists('La_Data_Row', false)) {
|
1007 |
+
interface La_Data_Row {
|
1008 |
+
public function get($name);
|
1009 |
+
|
1010 |
+
public function set($name, $value);
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
} //end La_Data_Row
|
1014 |
+
|
1015 |
+
if (!class_exists('La_Data_Record', false)) {
|
1016 |
+
class La_Data_Record extends La_Object implements Iterator, La_Rpc_Serializable,
|
1017 |
+
La_Templates_HasAttributes, La_Data_Row {
|
1018 |
+
private $record;
|
1019 |
+
/**
|
1020 |
+
*
|
1021 |
+
* @var La_Data_RecordHeader
|
1022 |
+
*/
|
1023 |
+
private $header;
|
1024 |
+
private $position;
|
1025 |
+
|
1026 |
+
/**
|
1027 |
+
* Create record
|
1028 |
+
*
|
1029 |
+
* @param array $header
|
1030 |
+
* @param array $array values of record from array
|
1031 |
+
*/
|
1032 |
+
public function __construct($header, $array = array()) {
|
1033 |
+
if (is_array($header)) {
|
1034 |
+
$header = new La_Data_RecordHeader($header);
|
1035 |
+
}
|
1036 |
+
$this->header = $header;
|
1037 |
+
$this->record = array_values($array);
|
1038 |
+
while(count($this->record) < $this->header->getSize()) {
|
1039 |
+
$this->record[] = null;
|
1040 |
+
}
|
1041 |
+
}
|
1042 |
+
|
1043 |
+
function getAttributes() {
|
1044 |
+
$ret = array();
|
1045 |
+
foreach ($this as $name => $value) {
|
1046 |
+
$ret[$name] = $value;
|
1047 |
+
}
|
1048 |
+
return $ret;
|
1049 |
+
}
|
1050 |
+
|
1051 |
+
public function contains($id) {
|
1052 |
+
return $this->header->contains($id);
|
1053 |
+
}
|
1054 |
+
|
1055 |
+
public function get($id) {
|
1056 |
+
$index = $this->header->getIndex($id);
|
1057 |
+
return $this->record[$index];
|
1058 |
+
}
|
1059 |
+
|
1060 |
+
public function set($id, $value) {
|
1061 |
+
$index = $this->header->getIndex($id);
|
1062 |
+
$this->record[$index] = $value;
|
1063 |
+
}
|
1064 |
+
|
1065 |
+
public function add($id, $value) {
|
1066 |
+
$this->header->add($id);
|
1067 |
+
$this->set($id, $value);
|
1068 |
+
}
|
1069 |
+
|
1070 |
+
public function toObject() {
|
1071 |
+
return $this->record;
|
1072 |
+
}
|
1073 |
+
|
1074 |
+
public function loadFromObject(array $array) {
|
1075 |
+
$this->record = $array;
|
1076 |
+
}
|
1077 |
+
|
1078 |
+
public function toText() {
|
1079 |
+
return implode('-', $this->record);
|
1080 |
+
}
|
1081 |
+
|
1082 |
+
public function current() {
|
1083 |
+
if(!isset($this->record[$this->position])) {
|
1084 |
+
return null;
|
1085 |
+
}
|
1086 |
+
return $this->record[$this->position];
|
1087 |
+
}
|
1088 |
+
|
1089 |
+
public function key() {
|
1090 |
+
$ids = $this->header->getIds();
|
1091 |
+
return $ids[$this->position];
|
1092 |
+
}
|
1093 |
+
|
1094 |
+
public function next() {
|
1095 |
+
$this->position++;
|
1096 |
+
}
|
1097 |
+
|
1098 |
+
public function rewind() {
|
1099 |
+
$this->position = 0;
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
public function valid() {
|
1103 |
+
return $this->position < $this->header->getSize();
|
1104 |
+
}
|
1105 |
+
}
|
1106 |
+
|
1107 |
+
|
1108 |
+
} //end La_Data_Record
|
1109 |
+
|
1110 |
+
if (!class_exists('La_Data_Grid', false)) {
|
1111 |
+
class La_Data_Grid extends La_Object {
|
1112 |
+
/**
|
1113 |
+
* @var La_Data_RecordSet
|
1114 |
+
*/
|
1115 |
+
private $recordset;
|
1116 |
+
private $totalCount;
|
1117 |
+
|
1118 |
+
public function loadFromObject(stdClass $object) {
|
1119 |
+
$this->recordset = new La_Data_RecordSet();
|
1120 |
+
$this->recordset->loadFromObject($object->R);
|
1121 |
+
$this->totalCount = $object->C;
|
1122 |
+
}
|
1123 |
+
|
1124 |
+
/**
|
1125 |
+
* @return La_Data_RecordSet
|
1126 |
+
*/
|
1127 |
+
public function getRecordset() {
|
1128 |
+
return $this->recordset;
|
1129 |
+
}
|
1130 |
+
|
1131 |
+
public function getTotalCount() {
|
1132 |
+
return $this->totalCount;
|
1133 |
+
}
|
1134 |
+
}
|
1135 |
+
|
1136 |
+
|
1137 |
+
} //end La_Data_Grid
|
1138 |
+
|
1139 |
+
if (!class_exists('La_Data_Filter', false)) {
|
1140 |
+
class La_Data_Filter extends La_Object implements La_Rpc_Serializable {
|
1141 |
+
const LIKE = "L";
|
1142 |
+
const NOT_LIKE = "NL";
|
1143 |
+
const EQUALS = "E";
|
1144 |
+
const NOT_EQUALS = "NE";
|
1145 |
+
|
1146 |
+
const DATE_EQUALS = "D=";
|
1147 |
+
const DATE_GREATER = "D>";
|
1148 |
+
const DATE_LOWER = "D<";
|
1149 |
+
const DATE_EQUALS_GREATER = "D>=";
|
1150 |
+
const DATE_EQUALS_LOWER = "D<=";
|
1151 |
+
const DATERANGE_IS = "DP";
|
1152 |
+
const TIME_EQUALS = "T=";
|
1153 |
+
const TIME_GREATER = "T>";
|
1154 |
+
const TIME_LOWER = "T<";
|
1155 |
+
const TIME_EQUALS_GREATER = "T>=";
|
1156 |
+
const TIME_EQUALS_LOWER = "T<=";
|
1157 |
+
|
1158 |
+
const RANGE_TODAY = 'T';
|
1159 |
+
const RANGE_YESTERDAY = 'Y';
|
1160 |
+
const RANGE_LAST_7_DAYS = 'L7D';
|
1161 |
+
const RANGE_LAST_30_DAYS = 'L30D';
|
1162 |
+
const RANGE_LAST_90_DAYS = 'L90D';
|
1163 |
+
const RANGE_THIS_WEEK = 'TW';
|
1164 |
+
const RANGE_LAST_WEEK = 'LW';
|
1165 |
+
const RANGE_LAST_2WEEKS = 'L2W';
|
1166 |
+
const RANGE_LAST_WORKING_WEEK = 'LWW';
|
1167 |
+
const RANGE_THIS_MONTH = 'TM';
|
1168 |
+
const RANGE_LAST_MONTH = 'LM';
|
1169 |
+
const RANGE_THIS_YEAR = 'TY';
|
1170 |
+
const RANGE_LAST_YEAR = 'LY';
|
1171 |
+
|
1172 |
+
private $code;
|
1173 |
+
private $operator;
|
1174 |
+
private $value;
|
1175 |
+
|
1176 |
+
public function __construct($code, $operator, $value) {
|
1177 |
+
$this->code = $code;
|
1178 |
+
$this->operator = $operator;
|
1179 |
+
$this->value = $value;
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
public function toObject() {
|
1183 |
+
return array($this->code, $this->operator, $this->value);
|
1184 |
+
}
|
1185 |
+
|
1186 |
+
public function toText() {
|
1187 |
+
throw new La_Exception("Unsupported");
|
1188 |
+
}
|
1189 |
+
}
|
1190 |
+
|
1191 |
+
|
1192 |
+
} //end La_Data_Filter
|
1193 |
+
|
1194 |
+
if (!class_exists('La_Rpc_GridRequest', false)) {
|
1195 |
+
class La_Rpc_GridRequest extends La_Rpc_Request {
|
1196 |
+
|
1197 |
+
private $filters = array();
|
1198 |
+
|
1199 |
+
private $limit = '';
|
1200 |
+
private $offset = '';
|
1201 |
+
|
1202 |
+
private $sortColumn = '';
|
1203 |
+
private $sortAscending = false;
|
1204 |
+
|
1205 |
+
/**
|
1206 |
+
* @return La_Data_Grid
|
1207 |
+
*/
|
1208 |
+
public function getGrid() {
|
1209 |
+
$response = new La_Data_Grid();
|
1210 |
+
$response->loadFromObject($this->getStdResponse());
|
1211 |
+
return $response;
|
1212 |
+
}
|
1213 |
+
|
1214 |
+
public function getFilters() {
|
1215 |
+
return $this->filters;
|
1216 |
+
}
|
1217 |
+
|
1218 |
+
/**
|
1219 |
+
* adds filter to grid
|
1220 |
+
*
|
1221 |
+
* @param unknown_type $code
|
1222 |
+
* @param unknown_type $operator
|
1223 |
+
* @param unknown_type $value
|
1224 |
+
*/
|
1225 |
+
public function addFilter($code, $operator, $value) {
|
1226 |
+
$this->filters[] = new La_Data_Filter($code, $operator, $value);
|
1227 |
+
}
|
1228 |
+
|
1229 |
+
public function setLimit($offset, $limit) {
|
1230 |
+
$this->offset = $offset;
|
1231 |
+
$this->limit = $limit;
|
1232 |
+
}
|
1233 |
+
|
1234 |
+
public function setSorting($sortColumn, $sortAscending = false) {
|
1235 |
+
$this->sortColumn = $sortColumn;
|
1236 |
+
$this->sortAscending = $sortAscending;
|
1237 |
+
}
|
1238 |
+
|
1239 |
+
public function send() {
|
1240 |
+
if(count($this->filters) > 0) {
|
1241 |
+
$this->addParam("filters", $this->addFiltersParameter());
|
1242 |
+
}
|
1243 |
+
if($this->sortColumn !== '') {
|
1244 |
+
$this->addParam("sort_col", $this->sortColumn);
|
1245 |
+
$this->addParam("sort_asc", ($this->sortAscending ? 'true' : 'false'));
|
1246 |
+
}
|
1247 |
+
if($this->offset !== '') {
|
1248 |
+
$this->addParam("offset", $this->offset);
|
1249 |
+
}
|
1250 |
+
if($this->limit !== '') {
|
1251 |
+
$this->addParam("limit", $this->limit);
|
1252 |
+
}
|
1253 |
+
|
1254 |
+
parent::send();
|
1255 |
+
}
|
1256 |
+
|
1257 |
+
private function addFiltersParameter() {
|
1258 |
+
$filters = new La_Rpc_Array();
|
1259 |
+
|
1260 |
+
foreach($this->filters as $filter) {
|
1261 |
+
$filters->add($filter);
|
1262 |
+
}
|
1263 |
+
|
1264 |
+
return $filters;
|
1265 |
+
}
|
1266 |
+
}
|
1267 |
+
|
1268 |
+
|
1269 |
+
|
1270 |
+
} //end La_Rpc_GridRequest
|
1271 |
+
|
1272 |
+
if (!class_exists('La_Data_RecordSet', false)) {
|
1273 |
+
class La_Data_RecordSet extends La_Object implements IteratorAggregate, La_Rpc_Serializable {
|
1274 |
+
|
1275 |
+
const SORT_ASC = 'ASC';
|
1276 |
+
const SORT_DESC = 'DESC';
|
1277 |
+
|
1278 |
+
protected $_array;
|
1279 |
+
/**
|
1280 |
+
* @var La_Data_RecordHeader
|
1281 |
+
*/
|
1282 |
+
private $_header;
|
1283 |
+
|
1284 |
+
function __construct() {
|
1285 |
+
$this->init();
|
1286 |
+
}
|
1287 |
+
|
1288 |
+
public function loadFromArray($rows) {
|
1289 |
+
$this->setHeader($rows[0]);
|
1290 |
+
|
1291 |
+
for ($i = 1; $i < count($rows); $i++) {
|
1292 |
+
$this->add($rows[$i]);
|
1293 |
+
}
|
1294 |
+
}
|
1295 |
+
|
1296 |
+
public function setHeader($header) {
|
1297 |
+
if($header instanceof La_Data_RecordHeader) {
|
1298 |
+
$this->_header = $header;
|
1299 |
+
return;
|
1300 |
+
}
|
1301 |
+
$this->_header = new La_Data_RecordHeader($header);
|
1302 |
+
}
|
1303 |
+
|
1304 |
+
/**
|
1305 |
+
* @return La_Data_RecordHeader
|
1306 |
+
*/
|
1307 |
+
public function getHeader() {
|
1308 |
+
return $this->_header;
|
1309 |
+
}
|
1310 |
+
|
1311 |
+
public function addRecordAtStart(La_Data_Record $record) {
|
1312 |
+
array_unshift($this->_array, $record);
|
1313 |
+
}
|
1314 |
+
|
1315 |
+
public function addRecord(La_Data_Record $record) {
|
1316 |
+
$this->_array[] = $record;
|
1317 |
+
}
|
1318 |
+
|
1319 |
+
/**
|
1320 |
+
* Adds new row to RecordSet
|
1321 |
+
*
|
1322 |
+
* @param array $record array of data for all columns in record
|
1323 |
+
*/
|
1324 |
+
public function add($record) {
|
1325 |
+
$this->addRecord($this->getRecordObject($record));
|
1326 |
+
}
|
1327 |
+
|
1328 |
+
/**
|
1329 |
+
* @return La_Data_Record
|
1330 |
+
*/
|
1331 |
+
public function createRecord() {
|
1332 |
+
return new La_Data_Record($this->_header);
|
1333 |
+
}
|
1334 |
+
|
1335 |
+
public function toObject() {
|
1336 |
+
$response = array();
|
1337 |
+
$response[] = $this->_header->toObject();
|
1338 |
+
foreach ($this->_array as $record) {
|
1339 |
+
$response[] = $record->toObject();
|
1340 |
+
}
|
1341 |
+
return $response;
|
1342 |
+
}
|
1343 |
+
|
1344 |
+
public function loadFromObject(array $array) {
|
1345 |
+
$this->_header = new La_Data_RecordHeader($array[0]);
|
1346 |
+
for($i = 1; $i < count($array);$i++) {
|
1347 |
+
$record = new La_Data_Record($this->_header);
|
1348 |
+
$record->loadFromObject($array[$i]);
|
1349 |
+
$this->loadRecordFromObject($record);
|
1350 |
+
}
|
1351 |
+
}
|
1352 |
+
|
1353 |
+
public function sort($column, $sortType = 'ASC') {
|
1354 |
+
if (!$this->_header->contains($column)) {
|
1355 |
+
throw new La_Exception('Undefined column');
|
1356 |
+
}
|
1357 |
+
$sorter = new La_Data_RecordSet_Sorter($column, $sortType);
|
1358 |
+
$this->_array = $sorter->sort($this->_array);
|
1359 |
+
}
|
1360 |
+
|
1361 |
+
protected function loadRecordFromObject(La_Data_Record $record) {
|
1362 |
+
$this->_array[] = $record;
|
1363 |
+
}
|
1364 |
+
|
1365 |
+
public function toArray() {
|
1366 |
+
$response = array();
|
1367 |
+
foreach ($this->_array as $record) {
|
1368 |
+
$response[] = $record->getAttributes();
|
1369 |
+
}
|
1370 |
+
return $response;
|
1371 |
+
}
|
1372 |
+
|
1373 |
+
public function toText() {
|
1374 |
+
$text = '';
|
1375 |
+
foreach ($this->_array as $record) {
|
1376 |
+
$text .= $record->toText() . "<br>\n";
|
1377 |
+
}
|
1378 |
+
return $text;
|
1379 |
+
}
|
1380 |
+
|
1381 |
+
/**
|
1382 |
+
* Return number of rows in recordset
|
1383 |
+
*
|
1384 |
+
* @return integer
|
1385 |
+
*/
|
1386 |
+
public function getSize() {
|
1387 |
+
return count($this->_array);
|
1388 |
+
}
|
1389 |
+
|
1390 |
+
/**
|
1391 |
+
* @return La_Data_Record
|
1392 |
+
*/
|
1393 |
+
public function get($i) {
|
1394 |
+
return $this->_array[$i];
|
1395 |
+
}
|
1396 |
+
|
1397 |
+
/**
|
1398 |
+
* @param array/La_Data_Record $record
|
1399 |
+
* @return La_Data_Record
|
1400 |
+
*/
|
1401 |
+
private function getRecordObject($record) {
|
1402 |
+
if(!($record instanceof La_Data_Record)) {
|
1403 |
+
$record = new La_Data_Record($this->_header->toArray(), $record);
|
1404 |
+
}
|
1405 |
+
return $record;
|
1406 |
+
}
|
1407 |
+
|
1408 |
+
private function init() {
|
1409 |
+
$this->_array = array();
|
1410 |
+
$this->_header = new La_Data_RecordHeader();
|
1411 |
+
}
|
1412 |
+
|
1413 |
+
public function clear() {
|
1414 |
+
$this->init();
|
1415 |
+
}
|
1416 |
+
|
1417 |
+
public function load(La_SqlBuilder_SelectBuilder $select) {
|
1418 |
+
}
|
1419 |
+
|
1420 |
+
/**
|
1421 |
+
*
|
1422 |
+
* @return ArrayIterator
|
1423 |
+
*/
|
1424 |
+
public function getIterator() {
|
1425 |
+
return new ArrayIterator($this->_array);
|
1426 |
+
}
|
1427 |
+
|
1428 |
+
public function getRecord($keyValue = null) {
|
1429 |
+
if(!array_key_exists($keyValue, $this->_array)) {
|
1430 |
+
return $this->createRecord();
|
1431 |
+
}
|
1432 |
+
return $this->_array[$keyValue];
|
1433 |
+
}
|
1434 |
+
|
1435 |
+
public function addColumn($id, $defaultValue = "") {
|
1436 |
+
$this->_header->add($id);
|
1437 |
+
foreach ($this->_array as $record) {
|
1438 |
+
$record->add($id, $defaultValue);
|
1439 |
+
}
|
1440 |
+
}
|
1441 |
+
|
1442 |
+
/**
|
1443 |
+
* Creates shalow copy of recordset containing only headers
|
1444 |
+
*
|
1445 |
+
* @return La_Data_RecordSet
|
1446 |
+
*/
|
1447 |
+
public function toShalowRecordSet() {
|
1448 |
+
$copy = new La_Data_RecordSet();
|
1449 |
+
$copy->setHeader($this->_header->toArray());
|
1450 |
+
return $copy;
|
1451 |
+
}
|
1452 |
+
}
|
1453 |
+
|
1454 |
+
class La_Data_RecordSet_Sorter {
|
1455 |
+
|
1456 |
+
private $sortColumn;
|
1457 |
+
private $sortType;
|
1458 |
+
|
1459 |
+
function __construct($column, $sortType) {
|
1460 |
+
$this->sortColumn = $column;
|
1461 |
+
$this->sortType = $sortType;
|
1462 |
+
}
|
1463 |
+
|
1464 |
+
public function sort(array $sortedArray) {
|
1465 |
+
usort($sortedArray, array($this, 'compareRecords'));
|
1466 |
+
return $sortedArray;
|
1467 |
+
}
|
1468 |
+
|
1469 |
+
private function compareRecords($record1, $record2) {
|
1470 |
+
if ($record1->get($this->sortColumn) == $record2->get($this->sortColumn)) {
|
1471 |
+
return 0;
|
1472 |
+
}
|
1473 |
+
return $this->compare($record1->get($this->sortColumn), $record2->get($this->sortColumn));
|
1474 |
+
}
|
1475 |
+
|
1476 |
+
private function compare($value1, $value2) {
|
1477 |
+
if ($this->sortType == La_Data_RecordSet::SORT_ASC) {
|
1478 |
+
return ($value1 < $value2) ? -1 : 1;
|
1479 |
+
}
|
1480 |
+
return ($value1 < $value2) ? 1 : -1;
|
1481 |
+
}
|
1482 |
+
}
|
1483 |
+
|
1484 |
+
} //end La_Data_RecordSet
|
1485 |
+
|
1486 |
+
if (!class_exists('La_Data_IndexedRecordSet', false)) {
|
1487 |
+
class La_Data_IndexedRecordSet extends La_Data_RecordSet {
|
1488 |
+
private $key;
|
1489 |
+
|
1490 |
+
/**
|
1491 |
+
*
|
1492 |
+
* @param int $keyIndex specifies which column should be used as a key
|
1493 |
+
*/
|
1494 |
+
function __construct($key) {
|
1495 |
+
parent::__construct();
|
1496 |
+
$this->key = $key;
|
1497 |
+
}
|
1498 |
+
|
1499 |
+
public function addRecord(La_Data_Record $record) {
|
1500 |
+
$this->_array[$record->get($this->key)] = $record;
|
1501 |
+
}
|
1502 |
+
|
1503 |
+
/**
|
1504 |
+
* @param String $keyValue
|
1505 |
+
* @return La_Data_Record
|
1506 |
+
*/
|
1507 |
+
public function createRecord($keyValue = null) {
|
1508 |
+
if($keyValue === null) {
|
1509 |
+
return parent::createRecord();
|
1510 |
+
}
|
1511 |
+
if(!array_key_exists($keyValue, $this->_array)) {
|
1512 |
+
$record = $this->createRecord();
|
1513 |
+
$record->set($this->key, $keyValue);
|
1514 |
+
$this->addRecord($record);
|
1515 |
+
}
|
1516 |
+
return $this->_array[$keyValue];
|
1517 |
+
}
|
1518 |
+
|
1519 |
+
protected function loadRecordFromObject(La_Data_Record $record) {
|
1520 |
+
$this->_array[$record->get($this->key)] = $record;
|
1521 |
+
}
|
1522 |
+
|
1523 |
+
/**
|
1524 |
+
* @param String $keyValue
|
1525 |
+
* @return La_Data_Record
|
1526 |
+
*/
|
1527 |
+
public function getRecord($keyValue = null) {
|
1528 |
+
if (!isset($this->_array[$keyValue])) {
|
1529 |
+
throw new La_Data_RecordSetNoRowException($keyValue);
|
1530 |
+
}
|
1531 |
+
return $this->_array[$keyValue];
|
1532 |
+
}
|
1533 |
+
|
1534 |
+
/**
|
1535 |
+
* @param String $keyValue
|
1536 |
+
* @return boolean
|
1537 |
+
*/
|
1538 |
+
public function existsRecord($keyValue) {
|
1539 |
+
return isset($this->_array[$keyValue]);
|
1540 |
+
}
|
1541 |
+
|
1542 |
+
/**
|
1543 |
+
* @param String $sortOptions (SORT_ASC, SORT_DESC, SORT_REGULAR, SORT_NUMERIC, SORT_STRING)
|
1544 |
+
* @return boolean
|
1545 |
+
*/
|
1546 |
+
public function sortByKeyValue($sortOptions) {
|
1547 |
+
return array_multisort($this->_array, $sortOptions);
|
1548 |
+
}
|
1549 |
+
}
|
1550 |
+
|
1551 |
+
|
1552 |
+
} //end La_Data_IndexedRecordSet
|
1553 |
+
|
1554 |
+
if (!class_exists('La_Net_Http_Request', false)) {
|
1555 |
+
class La_Net_Http_Request extends La_Object {
|
1556 |
+
const CRLF = "\r\n";
|
1557 |
+
|
1558 |
+
private $method = 'GET';
|
1559 |
+
private $url;
|
1560 |
+
|
1561 |
+
//proxy server
|
1562 |
+
private $proxyServer = '';
|
1563 |
+
private $proxyPort = '';
|
1564 |
+
private $proxyUser = '';
|
1565 |
+
private $proxyPassword = '';
|
1566 |
+
|
1567 |
+
//URL components
|
1568 |
+
private $scheme = 'http';
|
1569 |
+
private $host = '';
|
1570 |
+
private $port = 80;
|
1571 |
+
private $http_user = '';
|
1572 |
+
private $http_password = '';
|
1573 |
+
private $path = '';
|
1574 |
+
private $query = '';
|
1575 |
+
private $fragment = '';
|
1576 |
+
private $cookies = '';
|
1577 |
+
|
1578 |
+
private $body = '';
|
1579 |
+
private $headers = array();
|
1580 |
+
|
1581 |
+
public function setCookies($cookies) {
|
1582 |
+
$this->cookies = $cookies;
|
1583 |
+
}
|
1584 |
+
|
1585 |
+
public function getCookies() {
|
1586 |
+
return $this->cookies;
|
1587 |
+
}
|
1588 |
+
|
1589 |
+
public function getCookiesHeader() {
|
1590 |
+
return "Cookie: " . $this->cookies;
|
1591 |
+
}
|
1592 |
+
|
1593 |
+
public function setUrl($url) {
|
1594 |
+
$this->url = $url;
|
1595 |
+
$this->parseUrl();
|
1596 |
+
}
|
1597 |
+
|
1598 |
+
public function getUrl() {
|
1599 |
+
return $this->url;
|
1600 |
+
}
|
1601 |
+
|
1602 |
+
private function parseUrl() {
|
1603 |
+
$components = @parse_url($this->url);
|
1604 |
+
if (!$components) {
|
1605 |
+
return;
|
1606 |
+
}
|
1607 |
+
if (array_key_exists('scheme', $components)) {
|
1608 |
+
$this->scheme = $components['scheme'];
|
1609 |
+
}
|
1610 |
+
if (array_key_exists('host', $components)) {
|
1611 |
+
$this->host = $components['host'];
|
1612 |
+
}
|
1613 |
+
if (array_key_exists('port', $components)) {
|
1614 |
+
$this->port = $components['port'];
|
1615 |
+
}
|
1616 |
+
if (array_key_exists('user', $components)) {
|
1617 |
+
$this->http_user = $components['user'];
|
1618 |
+
}
|
1619 |
+
if (array_key_exists('pass', $components)) {
|
1620 |
+
$this->http_password = $components['pass'];
|
1621 |
+
}
|
1622 |
+
if (array_key_exists('path', $components)) {
|
1623 |
+
$this->path = $components['path'];
|
1624 |
+
}
|
1625 |
+
if (array_key_exists('query', $components)) {
|
1626 |
+
$this->query = $components['query'];
|
1627 |
+
}
|
1628 |
+
if (array_key_exists('fragment', $components)) {
|
1629 |
+
$this->fragement = $components['fragment'];
|
1630 |
+
}
|
1631 |
+
}
|
1632 |
+
|
1633 |
+
public function getScheme() {
|
1634 |
+
return $this->scheme;
|
1635 |
+
}
|
1636 |
+
|
1637 |
+
public function getHost() {
|
1638 |
+
if (strlen($this->proxyServer)) {
|
1639 |
+
return $this->proxyServer;
|
1640 |
+
}
|
1641 |
+
return $this->host;
|
1642 |
+
}
|
1643 |
+
|
1644 |
+
public function getPort() {
|
1645 |
+
if (strlen($this->proxyServer)) {
|
1646 |
+
return $this->proxyPort;
|
1647 |
+
}
|
1648 |
+
|
1649 |
+
if (strlen($this->port)) {
|
1650 |
+
return $this->port;
|
1651 |
+
}
|
1652 |
+
return 80;
|
1653 |
+
}
|
1654 |
+
|
1655 |
+
public function getHttpUser() {
|
1656 |
+
return $this->http_user;
|
1657 |
+
}
|
1658 |
+
|
1659 |
+
public function setHttpUser($user) {
|
1660 |
+
$this->http_user = $user;
|
1661 |
+
}
|
1662 |
+
|
1663 |
+
public function getHttpPassword() {
|
1664 |
+
return $this->http_password;
|
1665 |
+
}
|
1666 |
+
|
1667 |
+
public function setHttpPassword($pass) {
|
1668 |
+
$this->http_password = $pass;
|
1669 |
+
}
|
1670 |
+
|
1671 |
+
public function getPath() {
|
1672 |
+
return $this->path;
|
1673 |
+
}
|
1674 |
+
|
1675 |
+
public function getQuery() {
|
1676 |
+
return $this->query;
|
1677 |
+
}
|
1678 |
+
|
1679 |
+
public function addQueryParam($name, $value) {
|
1680 |
+
if (is_array($value)) {
|
1681 |
+
foreach($value as $key => $subValue) {
|
1682 |
+
$this->addQueryParam($name."[".$key."]", $subValue);
|
1683 |
+
}
|
1684 |
+
return;
|
1685 |
+
}
|
1686 |
+
$this->query .= ($this->query == '') ? '?' : '&';
|
1687 |
+
$this->query .= $name.'='.urlencode($value);
|
1688 |
+
}
|
1689 |
+
|
1690 |
+
public function getFragemnt() {
|
1691 |
+
return $this->fragment;
|
1692 |
+
}
|
1693 |
+
|
1694 |
+
/**
|
1695 |
+
* Set if request method is GET or POST
|
1696 |
+
*
|
1697 |
+
* @param string $method possible values are POST or GET
|
1698 |
+
*/
|
1699 |
+
public function setMethod($method) {
|
1700 |
+
$method = strtoupper($method);
|
1701 |
+
if ($method != 'GET' && $method != 'POST') {
|
1702 |
+
throw new La_Exception('Unsupported HTTP method: ' . $method);
|
1703 |
+
}
|
1704 |
+
$this->method = $method;
|
1705 |
+
}
|
1706 |
+
|
1707 |
+
/**
|
1708 |
+
* get the request method
|
1709 |
+
*
|
1710 |
+
* @access public
|
1711 |
+
* @return string
|
1712 |
+
*/
|
1713 |
+
public function getMethod() {
|
1714 |
+
return $this->method;
|
1715 |
+
}
|
1716 |
+
|
1717 |
+
/**
|
1718 |
+
* In case request should be redirected through proxy server, set proxy server settings
|
1719 |
+
* This function should be called after function setHost !!!
|
1720 |
+
*
|
1721 |
+
* @param string $server
|
1722 |
+
* @param string $port
|
1723 |
+
* @param string $user
|
1724 |
+
* @param string $password
|
1725 |
+
*/
|
1726 |
+
public function setProxyServer($server, $port, $user, $password) {
|
1727 |
+
$this->proxyServer = $server;
|
1728 |
+
$this->proxyPort = $port;
|
1729 |
+
$this->proxyUser = $user;
|
1730 |
+
$this->proxyPassword = $password;
|
1731 |
+
}
|
1732 |
+
|
1733 |
+
public function getProxyServer() {
|
1734 |
+
return $this->proxyServer;
|
1735 |
+
}
|
1736 |
+
|
1737 |
+
public function getProxyPort() {
|
1738 |
+
return $this->proxyPort;
|
1739 |
+
}
|
1740 |
+
|
1741 |
+
public function getProxyUser() {
|
1742 |
+
return $this->proxyUser;
|
1743 |
+
}
|
1744 |
+
|
1745 |
+
public function getProxyPassword() {
|
1746 |
+
return $this->proxyPassword;
|
1747 |
+
}
|
1748 |
+
|
1749 |
+
public function setBody($body) {
|
1750 |
+
$this->body = $body;
|
1751 |
+
}
|
1752 |
+
|
1753 |
+
public function getBody() {
|
1754 |
+
return $this->body;
|
1755 |
+
}
|
1756 |
+
|
1757 |
+
/**
|
1758 |
+
* Set header value
|
1759 |
+
*
|
1760 |
+
* @param string $name
|
1761 |
+
* @param string $value
|
1762 |
+
*/
|
1763 |
+
public function setHeader($name, $value) {
|
1764 |
+
$this->headers[$name] = $value;
|
1765 |
+
}
|
1766 |
+
|
1767 |
+
/**
|
1768 |
+
* Get header value
|
1769 |
+
*
|
1770 |
+
* @param string $name
|
1771 |
+
* @return string
|
1772 |
+
*/
|
1773 |
+
public function getHeader($name) {
|
1774 |
+
if (array_key_exists($name, $this->headers)) {
|
1775 |
+
return $this->headers[$name];
|
1776 |
+
}
|
1777 |
+
return null;
|
1778 |
+
}
|
1779 |
+
|
1780 |
+
/**
|
1781 |
+
* Return array of headers
|
1782 |
+
*
|
1783 |
+
* @return array
|
1784 |
+
*/
|
1785 |
+
public function getHeaders() {
|
1786 |
+
$headers = array();
|
1787 |
+
foreach ($this->headers as $headerName => $headerValue) {
|
1788 |
+
$headers[] = "$headerName: $headerValue";
|
1789 |
+
}
|
1790 |
+
return $headers;
|
1791 |
+
}
|
1792 |
+
|
1793 |
+
private function initHeaders() {
|
1794 |
+
if ($this->getPort() == '80') {
|
1795 |
+
$this->setHeader('Host', $this->getHost());
|
1796 |
+
} else {
|
1797 |
+
$this->setHeader('Host', $this->getHost() . ':' . $this->getPort());
|
1798 |
+
}
|
1799 |
+
if (isset($_SERVER['HTTP_USER_AGENT'])) {
|
1800 |
+
$this->setHeader('User-Agent', $_SERVER['HTTP_USER_AGENT']);
|
1801 |
+
}
|
1802 |
+
if (isset($_SERVER['HTTP_ACCEPT'])) {
|
1803 |
+
$this->setHeader('Accept', $_SERVER['HTTP_ACCEPT']);
|
1804 |
+
}
|
1805 |
+
if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
|
1806 |
+
$this->setHeader('Accept-Charset', $_SERVER['HTTP_ACCEPT_CHARSET']);
|
1807 |
+
}
|
1808 |
+
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
1809 |
+
$this->setHeader('Accept-Language', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
1810 |
+
}
|
1811 |
+
if (isset($_SERVER['HTTP_REFERER'])) {
|
1812 |
+
$this->setHeader('Referer', $_SERVER['HTTP_REFERER']);
|
1813 |
+
}
|
1814 |
+
if ($this->getMethod() == 'POST' && !strlen($this->getHeader("Content-Type"))) {
|
1815 |
+
$this->setHeader("Content-Type", "application/x-www-form-urlencoded");
|
1816 |
+
}
|
1817 |
+
|
1818 |
+
$this->setHeader('Content-Length', strlen($this->getBody()));
|
1819 |
+
$this->setHeader('Connection', 'close');
|
1820 |
+
|
1821 |
+
if (strlen($this->proxyUser)) {
|
1822 |
+
$this->setHeader('Proxy-Authorization',
|
1823 |
+
'Basic ' . base64_encode ($this->proxyUser . ':' . $this->proxyPassword));
|
1824 |
+
}
|
1825 |
+
|
1826 |
+
}
|
1827 |
+
|
1828 |
+
public function getUri() {
|
1829 |
+
$uri = $this->getPath();
|
1830 |
+
if (strlen($this->getQuery())) {
|
1831 |
+
$uri .= '?' . $this->getQuery();
|
1832 |
+
}
|
1833 |
+
return $uri;
|
1834 |
+
}
|
1835 |
+
|
1836 |
+
public function toString() {
|
1837 |
+
$this->initHeaders();
|
1838 |
+
$out = sprintf('%s %s HTTP/1.0' . self::CRLF, $this->getMethod(), $this->getUri());
|
1839 |
+
$out .= implode(self::CRLF, $this->getHeaders()) . self::CRLF . $this->getCookiesHeader() . self::CRLF;
|
1840 |
+
$out .= self::CRLF . $this->getBody();
|
1841 |
+
return $out;
|
1842 |
+
}
|
1843 |
+
|
1844 |
+
}
|
1845 |
+
|
1846 |
+
} //end La_Net_Http_Request
|
1847 |
+
|
1848 |
+
if (!class_exists('La_Net_Http_ClientBase', false)) {
|
1849 |
+
abstract class La_Net_Http_ClientBase extends La_Object {
|
1850 |
+
const CONNECTION_TIMEOUT = 20;
|
1851 |
+
|
1852 |
+
//TODO: rename this method to "send()"
|
1853 |
+
/**
|
1854 |
+
* @param La_Net_Http_Request $request
|
1855 |
+
* @return La_Net_Http_Response
|
1856 |
+
*/
|
1857 |
+
public function execute(La_Net_Http_Request $request) {
|
1858 |
+
|
1859 |
+
if (!$this->isNetworkingEnabled()) {
|
1860 |
+
throw new La_Exception($this->_('Network connections are disabled'));
|
1861 |
+
}
|
1862 |
+
|
1863 |
+
if (!strlen($request->getUrl())) {
|
1864 |
+
throw new La_Exception('No URL defined.');
|
1865 |
+
}
|
1866 |
+
|
1867 |
+
$this->setProxyServer($request);
|
1868 |
+
if (La_Php::isFunctionEnabled('curl_init')) {
|
1869 |
+
return $this->executeWithCurl($request);
|
1870 |
+
} else {
|
1871 |
+
return $this->executeWithSocketOpen($request);
|
1872 |
+
}
|
1873 |
+
}
|
1874 |
+
|
1875 |
+
protected abstract function isNetworkingEnabled();
|
1876 |
+
|
1877 |
+
/**
|
1878 |
+
* @param La_Net_Http_Request $request
|
1879 |
+
* @return La_Net_Http_Response
|
1880 |
+
*/
|
1881 |
+
private function executeWithSocketOpen(La_Net_Http_Request $request) {
|
1882 |
+
$scheme = ($request->getScheme() == 'ssl' || $request->getScheme() == 'https') ? 'ssl://' : '';
|
1883 |
+
$proxySocket = @fsockopen($scheme . $request->getHost(), $request->getPort(), $errorNr,
|
1884 |
+
$errorMessage, self::CONNECTION_TIMEOUT);
|
1885 |
+
|
1886 |
+
if($proxySocket === false) {
|
1887 |
+
$gpfErrorMessage = $this->_sys('Could not connect to server: %s:%s, Failed with error: %s', $request->getHost(), $request->getPort(), $errorMessage);
|
1888 |
+
La_Log::error($gpfErrorMessage);
|
1889 |
+
throw new La_Exception($gpfErrorMessage);
|
1890 |
+
}
|
1891 |
+
|
1892 |
+
$requestText = $request->toString();
|
1893 |
+
|
1894 |
+
$result = @fwrite($proxySocket, $requestText);
|
1895 |
+
if($result === false || $result != strlen($requestText)) {
|
1896 |
+
@fclose($proxySocket);
|
1897 |
+
$gpfErrorMessage = $this->_sys('Could not send request to server %s:%s', $request->getHost(), $request->getPort());
|
1898 |
+
La_Log::error($gpfErrorMessage);
|
1899 |
+
throw new La_Exception($gpfErrorMessage);
|
1900 |
+
}
|
1901 |
+
|
1902 |
+
$result = '';
|
1903 |
+
while (false === @feof($proxySocket)) {
|
1904 |
+
try {
|
1905 |
+
if(false === ($data = @fread($proxySocket, 8192))) {
|
1906 |
+
La_Log::error($this->_sys('Could not read from proxy socket'));
|
1907 |
+
throw new La_Exception("could not read from proxy socket");
|
1908 |
+
}
|
1909 |
+
$result .= $data;
|
1910 |
+
} catch (Exception $e) {
|
1911 |
+
La_Log::error($this->_sys('Proxy failed: %s', $e->getMessage()));
|
1912 |
+
@fclose($proxySocket);
|
1913 |
+
throw new La_Exception($this->_('Proxy failed: %s', $e->getMessage()));
|
1914 |
+
}
|
1915 |
+
}
|
1916 |
+
@fclose($proxySocket);
|
1917 |
+
|
1918 |
+
$response = new La_Net_Http_Response();
|
1919 |
+
$response->setResponseText($result);
|
1920 |
+
|
1921 |
+
return $response;
|
1922 |
+
}
|
1923 |
+
|
1924 |
+
|
1925 |
+
/**
|
1926 |
+
* @param La_Net_Http_Request $request
|
1927 |
+
* @return La_Net_Http_Response
|
1928 |
+
* */
|
1929 |
+
private function executeWithCurl(La_Net_Http_Request $request) {
|
1930 |
+
$session = curl_init($request->getUrl());
|
1931 |
+
|
1932 |
+
if ($request->getMethod() == 'POST') {
|
1933 |
+
@curl_setopt ($session, CURLOPT_POST, true);
|
1934 |
+
@curl_setopt ($session, CURLOPT_POSTFIELDS, $request->getBody());
|
1935 |
+
}
|
1936 |
+
|
1937 |
+
$cookies = $request->getCookies();
|
1938 |
+
if($cookies) {
|
1939 |
+
@curl_setopt($session, CURLOPT_COOKIE, $cookies);
|
1940 |
+
}
|
1941 |
+
|
1942 |
+
@curl_setopt($session, CURLOPT_HEADER, true);
|
1943 |
+
@curl_setopt($session, CURLOPT_CONNECTTIMEOUT, self::CONNECTION_TIMEOUT);
|
1944 |
+
@curl_setopt($session, CURLOPT_HTTPHEADER, $request->getHeaders());
|
1945 |
+
@curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
|
1946 |
+
@curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
|
1947 |
+
if ($request->getHttpPassword() != '' && $request->getHttpUser() != '') {
|
1948 |
+
@curl_setopt($session, CURLOPT_USERPWD, $request->getHttpUser() . ":" . $request->getHttpPassword());
|
1949 |
+
@curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
1950 |
+
}
|
1951 |
+
@curl_setopt ($session, CURLOPT_SSL_VERIFYHOST, 0);
|
1952 |
+
@curl_setopt ($session, CURLOPT_SSL_VERIFYPEER, 0);
|
1953 |
+
|
1954 |
+
$this->setupCurlProxyServer($session, $request);
|
1955 |
+
|
1956 |
+
// Make the call
|
1957 |
+
$result = curl_exec($session);
|
1958 |
+
$error = curl_error($session);
|
1959 |
+
|
1960 |
+
curl_close($session);
|
1961 |
+
|
1962 |
+
if (strlen($error)) {
|
1963 |
+
throw new La_Exception("Curl error: " . $error);
|
1964 |
+
}
|
1965 |
+
|
1966 |
+
$response = new La_Net_Http_Response();
|
1967 |
+
$response->setResponseText($result);
|
1968 |
+
|
1969 |
+
return $response;
|
1970 |
+
}
|
1971 |
+
|
1972 |
+
protected function setProxyServer(La_Net_Http_Request $request) {
|
1973 |
+
$request->setProxyServer('', '', '', '');
|
1974 |
+
}
|
1975 |
+
|
1976 |
+
private function setupCurlProxyServer($curlSession, La_Net_Http_Request $request) {
|
1977 |
+
if (strlen($request->getProxyServer()) && strlen($request->getProxyPort())) {
|
1978 |
+
@curl_setopt($curlSession, CURLOPT_PROXY, $request->getProxyServer() . ':' . $request->getProxyPort());
|
1979 |
+
if (strlen($request->getProxyUser())) {
|
1980 |
+
@curl_setopt($curlSession, CURLOPT_PROXYUSERPWD, $request->getProxyUser() . ':' . $request->getProxyPassword());
|
1981 |
+
}
|
1982 |
+
}
|
1983 |
+
}
|
1984 |
+
}
|
1985 |
+
|
1986 |
+
} //end La_Net_Http_ClientBase
|
1987 |
+
|
1988 |
+
if (!class_exists('La_Net_Http_Response', false)) {
|
1989 |
+
class La_Net_Http_Response extends La_Object {
|
1990 |
+
|
1991 |
+
private $responseText = '';
|
1992 |
+
private $header = '';
|
1993 |
+
private $body = '';
|
1994 |
+
|
1995 |
+
public function setResponseText($responseText) {
|
1996 |
+
$this->responseText = $responseText;
|
1997 |
+
$this->parse();
|
1998 |
+
}
|
1999 |
+
|
2000 |
+
public function getHeadersText() {
|
2001 |
+
return $this->header;
|
2002 |
+
}
|
2003 |
+
|
2004 |
+
private function getHeaderPosition($pos) {
|
2005 |
+
return strpos($this->responseText, "\r\n\r\nHTTP", $pos);
|
2006 |
+
}
|
2007 |
+
|
2008 |
+
public function getBody() {
|
2009 |
+
return $this->body;
|
2010 |
+
}
|
2011 |
+
|
2012 |
+
private function parse() {
|
2013 |
+
$offset = 0;
|
2014 |
+
while ($this->getHeaderPosition($offset)) {
|
2015 |
+
$offset = $this->getHeaderPosition($offset) + 4;
|
2016 |
+
}
|
2017 |
+
if (($pos = strpos($this->responseText, "\r\n\r\n", $offset)) > 0) {
|
2018 |
+
$this->body = substr($this->responseText, $pos + 4);
|
2019 |
+
$this->header = substr($this->responseText, $offset, $pos - $offset);
|
2020 |
+
return;
|
2021 |
+
}
|
2022 |
+
$this->body = '';
|
2023 |
+
$this->header = '';
|
2024 |
+
}
|
2025 |
+
}
|
2026 |
+
|
2027 |
+
} //end La_Net_Http_Response
|
2028 |
+
|
2029 |
+
if (!class_exists('La_Rpc_Form', false)) {
|
2030 |
+
class La_Rpc_Form extends La_Object implements La_Rpc_Serializable, IteratorAggregate {
|
2031 |
+
const FIELD_NAME = "name";
|
2032 |
+
const FIELD_VALUE = "value";
|
2033 |
+
const FIELD_ERROR = "error";
|
2034 |
+
const FIELD_VALUES = "values";
|
2035 |
+
|
2036 |
+
private $isError = false;
|
2037 |
+
private $errorMessage = "";
|
2038 |
+
private $infoMessage = "";
|
2039 |
+
private $status;
|
2040 |
+
/**
|
2041 |
+
* @var La_Data_IndexedRecordSet
|
2042 |
+
*/
|
2043 |
+
private $fields;
|
2044 |
+
/**
|
2045 |
+
* @var La_Rpc_Form_Validator_FormValidatorCollection
|
2046 |
+
*/
|
2047 |
+
private $validators;
|
2048 |
+
|
2049 |
+
public function __construct(La_Rpc_Params $params = null) {
|
2050 |
+
$this->fields = new La_Data_IndexedRecordSet(self::FIELD_NAME);
|
2051 |
+
|
2052 |
+
$header = new La_Data_RecordHeader();
|
2053 |
+
$header->add(self::FIELD_NAME);
|
2054 |
+
$header->add(self::FIELD_VALUE);
|
2055 |
+
$header->add(self::FIELD_VALUES);
|
2056 |
+
$header->add(self::FIELD_ERROR);
|
2057 |
+
$this->fields->setHeader($header);
|
2058 |
+
|
2059 |
+
$this->validator = new La_Rpc_Form_Validator_FormValidatorCollection($this);
|
2060 |
+
|
2061 |
+
if($params) {
|
2062 |
+
$this->loadFieldsFromArray($params->get("fields"));
|
2063 |
+
}
|
2064 |
+
}
|
2065 |
+
|
2066 |
+
/**
|
2067 |
+
* @param $validator
|
2068 |
+
* @param $fieldName
|
2069 |
+
* @param $fieldLabel
|
2070 |
+
*/
|
2071 |
+
public function addValidator(La_Rpc_Form_Validator_Validator $validator, $fieldName, $fieldLabel = null) {
|
2072 |
+
$this->validator->addValidator($validator, $fieldName, $fieldLabel);
|
2073 |
+
}
|
2074 |
+
|
2075 |
+
/**
|
2076 |
+
* @return boolean
|
2077 |
+
*/
|
2078 |
+
public function validate() {
|
2079 |
+
return $this->validator->validate();
|
2080 |
+
}
|
2081 |
+
|
2082 |
+
public function loadFieldsFromArray($fields) {
|
2083 |
+
for ($i = 1; $i < count($fields); $i++) {
|
2084 |
+
$field = $fields[$i];
|
2085 |
+
$this->fields->add($field);
|
2086 |
+
}
|
2087 |
+
}
|
2088 |
+
|
2089 |
+
/**
|
2090 |
+
*
|
2091 |
+
* @return ArrayIterator
|
2092 |
+
*/
|
2093 |
+
public function getIterator() {
|
2094 |
+
return $this->fields->getIterator();
|
2095 |
+
}
|
2096 |
+
|
2097 |
+
public function addField($name, $value) {
|
2098 |
+
$record = $this->fields->createRecord($name);
|
2099 |
+
$record->set(self::FIELD_VALUE, $value);
|
2100 |
+
}
|
2101 |
+
|
2102 |
+
public function setField($name, $value, $values = null, $error = "") {
|
2103 |
+
$record = $this->fields->createRecord($name);
|
2104 |
+
$record->set(self::FIELD_VALUE, $value);
|
2105 |
+
$record->set(self::FIELD_VALUES, $values);
|
2106 |
+
$record->set(self::FIELD_ERROR, $error);
|
2107 |
+
}
|
2108 |
+
|
2109 |
+
public function setFieldError($name, $error) {
|
2110 |
+
$this->isError = true;
|
2111 |
+
$record = $this->fields->getRecord($name);
|
2112 |
+
$record->set(self::FIELD_ERROR, $error);
|
2113 |
+
}
|
2114 |
+
|
2115 |
+
public function getFieldValue($name) {
|
2116 |
+
$record = $this->fields->getRecord($name);
|
2117 |
+
return $record->get(self::FIELD_VALUE);
|
2118 |
+
}
|
2119 |
+
|
2120 |
+
public function getFieldError($name) {
|
2121 |
+
$record = $this->fields->getRecord($name);
|
2122 |
+
return $record->get(self::FIELD_ERROR);
|
2123 |
+
}
|
2124 |
+
|
2125 |
+
public function existsField($name) {
|
2126 |
+
return $this->fields->existsRecord($name);
|
2127 |
+
}
|
2128 |
+
|
2129 |
+
public function load(La_Data_Row $row) {
|
2130 |
+
foreach($row as $columnName => $columnValue) {
|
2131 |
+
$this->setField($columnName, $row->get($columnName));
|
2132 |
+
}
|
2133 |
+
}
|
2134 |
+
|
2135 |
+
/**
|
2136 |
+
* @return La_Data_IndexedRecordSet
|
2137 |
+
*/
|
2138 |
+
public function getFields() {
|
2139 |
+
return $this->fields;
|
2140 |
+
}
|
2141 |
+
|
2142 |
+
public function fill(La_Data_Row $row) {
|
2143 |
+
foreach ($this->fields as $field) {
|
2144 |
+
try {
|
2145 |
+
$row->set($field->get(self::FIELD_NAME), $field->get(self::FIELD_VALUE));
|
2146 |
+
} catch (Exception $e) {
|
2147 |
+
}
|
2148 |
+
}
|
2149 |
+
}
|
2150 |
+
|
2151 |
+
public function toObject() {
|
2152 |
+
$response = new stdClass();
|
2153 |
+
$response->F = $this->fields->toObject();
|
2154 |
+
if ($this->isSuccessful()) {
|
2155 |
+
$response->S = Gpf::YES;
|
2156 |
+
$response->M = $this->infoMessage;
|
2157 |
+
} else {
|
2158 |
+
$response->S = Gpf::NO;
|
2159 |
+
$response->M = $this->errorMessage;
|
2160 |
+
}
|
2161 |
+
if (!strlen($response->M)) {
|
2162 |
+
unset($response->M);
|
2163 |
+
}
|
2164 |
+
return $response;
|
2165 |
+
}
|
2166 |
+
|
2167 |
+
public function loadFromObject(stdClass $object) {
|
2168 |
+
if ($object->success == Gpf::YES) {
|
2169 |
+
$this->setInfoMessage($object->message);
|
2170 |
+
} else {
|
2171 |
+
$this->setErrorMessage($object->message);
|
2172 |
+
}
|
2173 |
+
|
2174 |
+
$this->fields = new La_Data_IndexedRecordSet(self::FIELD_NAME);
|
2175 |
+
$this->fields->loadFromObject($object->fields);
|
2176 |
+
}
|
2177 |
+
|
2178 |
+
public function toText() {
|
2179 |
+
return var_dump($this->toObject());
|
2180 |
+
}
|
2181 |
+
|
2182 |
+
public function setErrorMessage($message) {
|
2183 |
+
$this->isError = true;
|
2184 |
+
$this->errorMessage = $message;
|
2185 |
+
}
|
2186 |
+
|
2187 |
+
public function getErrorMessage() {
|
2188 |
+
if ($this->isError) {
|
2189 |
+
return $this->errorMessage;
|
2190 |
+
}
|
2191 |
+
return "";
|
2192 |
+
}
|
2193 |
+
|
2194 |
+
public function setInfoMessage($message) {
|
2195 |
+
$this->infoMessage = $message;
|
2196 |
+
}
|
2197 |
+
|
2198 |
+
public function setSuccessful() {
|
2199 |
+
$this->isError = false;
|
2200 |
+
}
|
2201 |
+
|
2202 |
+
public function getInfoMessage() {
|
2203 |
+
if ($this->isError) {
|
2204 |
+
return "";
|
2205 |
+
}
|
2206 |
+
return $this->infoMessage;
|
2207 |
+
}
|
2208 |
+
|
2209 |
+
|
2210 |
+
/**
|
2211 |
+
* @return boolean
|
2212 |
+
*/
|
2213 |
+
public function isSuccessful() {
|
2214 |
+
return !$this->isError;
|
2215 |
+
}
|
2216 |
+
|
2217 |
+
/**
|
2218 |
+
* @return boolean
|
2219 |
+
*/
|
2220 |
+
public function isError() {
|
2221 |
+
return $this->isError;
|
2222 |
+
}
|
2223 |
+
|
2224 |
+
public function getDefaultErrorMessage() {
|
2225 |
+
return $this->_('There were errors, please check highlighted fields');
|
2226 |
+
}
|
2227 |
+
}
|
2228 |
+
|
2229 |
+
|
2230 |
+
} //end La_Rpc_Form
|
2231 |
+
|
2232 |
+
if (!class_exists('La_Rpc_Form_Validator_FormValidatorCollection', false)) {
|
2233 |
+
class La_Rpc_Form_Validator_FormValidatorCollection extends La_Object {
|
2234 |
+
|
2235 |
+
/**
|
2236 |
+
* @var array<La_Rpc_Form_Validator_FieldValidator>
|
2237 |
+
*/
|
2238 |
+
private $validators;
|
2239 |
+
/**
|
2240 |
+
* @var La_Rpc_Form
|
2241 |
+
*/
|
2242 |
+
private $form;
|
2243 |
+
|
2244 |
+
public function __construct(La_Rpc_Form $form) {
|
2245 |
+
$this->form = $form;
|
2246 |
+
$this->validators = array();
|
2247 |
+
}
|
2248 |
+
|
2249 |
+
/**
|
2250 |
+
* @param $fieldName
|
2251 |
+
* @param $validator
|
2252 |
+
*/
|
2253 |
+
public function addValidator(La_Rpc_Form_Validator_Validator $validator, $fieldName, $fieldLabel = null) {
|
2254 |
+
if (!array_key_exists($fieldName, $this->validators)) {
|
2255 |
+
$this->validators[$fieldName] = new La_Rpc_Form_Validator_FieldValidator(($fieldLabel === null ? $fieldName : $fieldLabel));
|
2256 |
+
}
|
2257 |
+
$this->validators[$fieldName]->addValidator($validator);
|
2258 |
+
}
|
2259 |
+
|
2260 |
+
/**
|
2261 |
+
* @return boolean
|
2262 |
+
*/
|
2263 |
+
public function validate() {
|
2264 |
+
$errorMsg = false;
|
2265 |
+
foreach ($this->validators as $fieldName => $fieldValidator) {
|
2266 |
+
if (!$fieldValidator->validate($this->form->getFieldValue($fieldName))) {
|
2267 |
+
$errorMsg = true;
|
2268 |
+
$this->form->setFieldError($fieldName, $fieldValidator->getMessage());
|
2269 |
+
}
|
2270 |
+
}
|
2271 |
+
if ($errorMsg) {
|
2272 |
+
$this->form->setErrorMessage($this->form->getDefaultErrorMessage());
|
2273 |
+
}
|
2274 |
+
return !$errorMsg;
|
2275 |
+
}
|
2276 |
+
}
|
2277 |
+
|
2278 |
+
} //end La_Rpc_Form_Validator_FormValidatorCollection
|
2279 |
+
|
2280 |
+
if (!class_exists('La_Rpc_FormRequest', false)) {
|
2281 |
+
class La_Rpc_FormRequest extends La_Rpc_Request {
|
2282 |
+
/**
|
2283 |
+
* @var La_Rpc_Form
|
2284 |
+
*/
|
2285 |
+
private $fields;
|
2286 |
+
|
2287 |
+
public function __construct($className, $methodName, La_Api_Session $apiSessionObject = null) {
|
2288 |
+
parent::__construct($className, $methodName, $apiSessionObject);
|
2289 |
+
$this->fields = new La_Rpc_Form();
|
2290 |
+
}
|
2291 |
+
|
2292 |
+
public function send() {
|
2293 |
+
$this->addParam('fields', $this->fields->getFields());
|
2294 |
+
parent::send();
|
2295 |
+
}
|
2296 |
+
|
2297 |
+
/**
|
2298 |
+
* @return La_Rpc_Form
|
2299 |
+
*/
|
2300 |
+
public function getForm() {
|
2301 |
+
$response = new La_Rpc_Form();
|
2302 |
+
$response->loadFromObject($this->getStdResponse());
|
2303 |
+
return $response;
|
2304 |
+
}
|
2305 |
+
|
2306 |
+
public function setField($name, $value) {
|
2307 |
+
if (is_scalar($value) || $value instanceof La_Rpc_Serializable) {
|
2308 |
+
$this->fields->setField($name, $value);
|
2309 |
+
} else {
|
2310 |
+
throw new La_Exception("Not supported value");
|
2311 |
+
}
|
2312 |
+
}
|
2313 |
+
|
2314 |
+
public function setFields(La_Data_IndexedRecordSet $fields) {
|
2315 |
+
$this->fields->loadFieldsFromArray($fields->toArray());
|
2316 |
+
}
|
2317 |
+
}
|
2318 |
+
|
2319 |
+
} //end La_Rpc_FormRequest
|
2320 |
+
|
2321 |
+
if (!class_exists('La_Rpc_RecordSetRequest', false)) {
|
2322 |
+
class La_Rpc_RecordSetRequest extends La_Rpc_Request {
|
2323 |
+
|
2324 |
+
/**
|
2325 |
+
* @return La_Data_IndexedRecordSet
|
2326 |
+
*/
|
2327 |
+
public function getIndexedRecordSet($key) {
|
2328 |
+
$response = new La_Data_IndexedRecordSet($key);
|
2329 |
+
$response->loadFromObject($this->getStdResponse());
|
2330 |
+
return $response;
|
2331 |
+
}
|
2332 |
+
|
2333 |
+
|
2334 |
+
/**
|
2335 |
+
* @return La_Data_RecordSet
|
2336 |
+
*/
|
2337 |
+
public function getRecordSet() {
|
2338 |
+
$response = new La_Data_RecordSet();
|
2339 |
+
$response->loadFromObject($this->getStdResponse());
|
2340 |
+
return $response;
|
2341 |
+
}
|
2342 |
+
}
|
2343 |
+
|
2344 |
+
|
2345 |
+
} //end La_Rpc_RecordSetRequest
|
2346 |
+
|
2347 |
+
if (!class_exists('La_Rpc_DataRequest', false)) {
|
2348 |
+
class La_Rpc_DataRequest extends La_Rpc_Request {
|
2349 |
+
/**
|
2350 |
+
* @var La_Rpc_Data
|
2351 |
+
*/
|
2352 |
+
private $data;
|
2353 |
+
|
2354 |
+
private $filters = array();
|
2355 |
+
|
2356 |
+
public function __construct($className, $methodName, La_Api_Session $apiSessionObject = null) {
|
2357 |
+
parent::__construct($className, $methodName, $apiSessionObject);
|
2358 |
+
$this->data = new La_Rpc_Data();
|
2359 |
+
}
|
2360 |
+
|
2361 |
+
/**
|
2362 |
+
* @return La_Rpc_Data
|
2363 |
+
*/
|
2364 |
+
public function getData() {
|
2365 |
+
$response = new La_Rpc_Data();
|
2366 |
+
$response->loadFromObject($this->getStdResponse());
|
2367 |
+
return $response;
|
2368 |
+
}
|
2369 |
+
|
2370 |
+
public function setField($name, $value) {
|
2371 |
+
if (is_scalar($value) || $value instanceof La_Rpc_Serializable) {
|
2372 |
+
$this->data->setParam($name, $value);
|
2373 |
+
} else {
|
2374 |
+
throw new La_Exception("Not supported value");
|
2375 |
+
}
|
2376 |
+
}
|
2377 |
+
|
2378 |
+
/**
|
2379 |
+
* adds filter to grid
|
2380 |
+
*
|
2381 |
+
* @param unknown_type $code
|
2382 |
+
* @param unknown_type $operator
|
2383 |
+
* @param unknown_type $value
|
2384 |
+
*/
|
2385 |
+
public function addFilter($code, $operator, $value) {
|
2386 |
+
$this->filters[] = new La_Data_Filter($code, $operator, $value);
|
2387 |
+
}
|
2388 |
+
|
2389 |
+
public function send() {
|
2390 |
+
$this->addParam('data', $this->data->getParams());
|
2391 |
+
|
2392 |
+
if(count($this->filters) > 0) {
|
2393 |
+
$this->addParam("filters", $this->addFiltersParameter());
|
2394 |
+
}
|
2395 |
+
parent::send();
|
2396 |
+
}
|
2397 |
+
|
2398 |
+
private function addFiltersParameter() {
|
2399 |
+
$filters = new La_Rpc_Array();
|
2400 |
+
|
2401 |
+
foreach($this->filters as $filter) {
|
2402 |
+
$filters->add($filter);
|
2403 |
+
}
|
2404 |
+
|
2405 |
+
return $filters;
|
2406 |
+
}
|
2407 |
+
}
|
2408 |
+
|
2409 |
+
} //end La_Rpc_DataRequest
|
2410 |
+
|
2411 |
+
if (!class_exists('La_Rpc_Data', false)) {
|
2412 |
+
class La_Rpc_Data extends La_Object implements La_Rpc_Serializable {
|
2413 |
+
const NAME = "name";
|
2414 |
+
const VALUE = "value";
|
2415 |
+
const DATA = "data";
|
2416 |
+
const ID = "id";
|
2417 |
+
|
2418 |
+
/**
|
2419 |
+
* @var La_Data_IndexedRecordSet
|
2420 |
+
*/
|
2421 |
+
private $params;
|
2422 |
+
|
2423 |
+
/**
|
2424 |
+
* @var string
|
2425 |
+
*/
|
2426 |
+
private $id;
|
2427 |
+
|
2428 |
+
|
2429 |
+
/**
|
2430 |
+
* @var La_Rpc_FilterCollection
|
2431 |
+
*/
|
2432 |
+
private $filters;
|
2433 |
+
|
2434 |
+
/**
|
2435 |
+
* @var La_Data_IndexedRecordSet
|
2436 |
+
*/
|
2437 |
+
private $response;
|
2438 |
+
|
2439 |
+
/**
|
2440 |
+
*
|
2441 |
+
* @return La_Data_IndexedRecordSet
|
2442 |
+
*/
|
2443 |
+
public function getParams() {
|
2444 |
+
return $this->params;
|
2445 |
+
}
|
2446 |
+
|
2447 |
+
/**
|
2448 |
+
* Create instance to handle DataRequest
|
2449 |
+
*
|
2450 |
+
* @param La_Rpc_Params $params
|
2451 |
+
*/
|
2452 |
+
public function __construct(La_Rpc_Params $params = null) {
|
2453 |
+
if($params === null) {
|
2454 |
+
$params = new La_Rpc_Params();
|
2455 |
+
}
|
2456 |
+
|
2457 |
+
$this->filters = new La_Rpc_FilterCollection($params);
|
2458 |
+
|
2459 |
+
$this->params = new La_Data_IndexedRecordSet(self::NAME);
|
2460 |
+
$this->params->setHeader(array(self::NAME, self::VALUE));
|
2461 |
+
|
2462 |
+
if ($params->exists(self::DATA) !== null) {
|
2463 |
+
$this->loadParamsFromArray($params->get(self::DATA));
|
2464 |
+
}
|
2465 |
+
|
2466 |
+
$this->id = $params->get(self::ID);
|
2467 |
+
|
2468 |
+
$this->response = new La_Data_IndexedRecordSet(self::NAME);
|
2469 |
+
$this->response->setHeader(array(self::NAME, self::VALUE));
|
2470 |
+
}
|
2471 |
+
|
2472 |
+
public function addValues(array $values) {
|
2473 |
+
foreach ($values as $key => $value) {
|
2474 |
+
$this->setValue($key, $value);
|
2475 |
+
}
|
2476 |
+
}
|
2477 |
+
|
2478 |
+
/**
|
2479 |
+
* Return id
|
2480 |
+
*
|
2481 |
+
* @return string
|
2482 |
+
*/
|
2483 |
+
public function getId() {
|
2484 |
+
return $this->id;
|
2485 |
+
}
|
2486 |
+
|
2487 |
+
/**
|
2488 |
+
* Return parameter value
|
2489 |
+
*
|
2490 |
+
* @param String $name
|
2491 |
+
* @return unknown
|
2492 |
+
*/
|
2493 |
+
public function getParam($name) {
|
2494 |
+
try {
|
2495 |
+
return $this->params->getRecord($name)->get(self::VALUE);
|
2496 |
+
} catch (La_Data_RecordSetNoRowException $e) {
|
2497 |
+
return null;
|
2498 |
+
}
|
2499 |
+
}
|
2500 |
+
|
2501 |
+
public function setParam($name, $value) {
|
2502 |
+
self::setValueToRecordset($this->params, $name, $value);
|
2503 |
+
}
|
2504 |
+
|
2505 |
+
public function loadFromObject(array $object) {
|
2506 |
+
$this->response->loadFromObject($object);
|
2507 |
+
$this->params->loadFromObject($object);
|
2508 |
+
}
|
2509 |
+
|
2510 |
+
/**
|
2511 |
+
* @return La_Rpc_FilterCollection
|
2512 |
+
*/
|
2513 |
+
public function getFilters() {
|
2514 |
+
return $this->filters;
|
2515 |
+
}
|
2516 |
+
|
2517 |
+
private static function setValueToRecordset(La_Data_IndexedRecordSet $recordset, $name, $value) {
|
2518 |
+
try {
|
2519 |
+
$record = $recordset->getRecord($name);
|
2520 |
+
} catch (La_Data_RecordSetNoRowException $e) {
|
2521 |
+
$record = $recordset->createRecord();
|
2522 |
+
$record->set(self::NAME, $name);
|
2523 |
+
$recordset->addRecord($record);
|
2524 |
+
}
|
2525 |
+
$record->set(self::VALUE, $value);
|
2526 |
+
}
|
2527 |
+
|
2528 |
+
public function setValue($name, $value) {
|
2529 |
+
self::setValueToRecordset($this->response, $name, $value);
|
2530 |
+
}
|
2531 |
+
|
2532 |
+
public function getSize() {
|
2533 |
+
return $this->response->getSize();
|
2534 |
+
}
|
2535 |
+
|
2536 |
+
public function getValue($name) {
|
2537 |
+
return $this->response->getRecord($name)->get(self::VALUE);
|
2538 |
+
}
|
2539 |
+
|
2540 |
+
public function toObject() {
|
2541 |
+
return $this->response->toObject();
|
2542 |
+
}
|
2543 |
+
|
2544 |
+
public function toText() {
|
2545 |
+
return $this->response->toText();
|
2546 |
+
}
|
2547 |
+
|
2548 |
+
private function loadParamsFromArray($data) {
|
2549 |
+
for ($i = 1; $i < count($data); $i++) {
|
2550 |
+
$this->params->add($data[$i]);
|
2551 |
+
}
|
2552 |
+
}
|
2553 |
+
}
|
2554 |
+
|
2555 |
+
} //end La_Rpc_Data
|
2556 |
+
|
2557 |
+
if (!class_exists('La_Rpc_FilterCollection', false)) {
|
2558 |
+
class La_Rpc_FilterCollection extends La_Object implements IteratorAggregate {
|
2559 |
+
|
2560 |
+
/**
|
2561 |
+
* @var array of La_Filter
|
2562 |
+
*/
|
2563 |
+
private $filters;
|
2564 |
+
|
2565 |
+
public function __construct(La_Rpc_Params $params = null) {
|
2566 |
+
$this->filters = array();
|
2567 |
+
if ($params != null) {
|
2568 |
+
$this->init($params);
|
2569 |
+
}
|
2570 |
+
}
|
2571 |
+
|
2572 |
+
/**
|
2573 |
+
* @return La_Rpc_FilterCollection
|
2574 |
+
*/
|
2575 |
+
public static function fromJson($json){
|
2576 |
+
$instance = new La_Rpc_FilterCollection();
|
2577 |
+
$filters = La_Rpc_Json::decodeStatic($json);
|
2578 |
+
foreach ($filters as $filter){
|
2579 |
+
$instance->add($filter);
|
2580 |
+
}
|
2581 |
+
return $instance;
|
2582 |
+
}
|
2583 |
+
|
2584 |
+
public function add(array $filterArray) {
|
2585 |
+
$this->filters[] = new La_Filter($filterArray);
|
2586 |
+
}
|
2587 |
+
|
2588 |
+
private function init(La_Rpc_Params $params) {
|
2589 |
+
$filtersArray = $params->get("filters");
|
2590 |
+
if (!is_array($filtersArray)) {
|
2591 |
+
return;
|
2592 |
+
}
|
2593 |
+
foreach ($filtersArray as $filterArray) {
|
2594 |
+
$this->add($filterArray);
|
2595 |
+
}
|
2596 |
+
}
|
2597 |
+
|
2598 |
+
/**
|
2599 |
+
*
|
2600 |
+
* @return ArrayIterator
|
2601 |
+
*/
|
2602 |
+
public function getIterator() {
|
2603 |
+
return new ArrayIterator($this->filters);
|
2604 |
+
}
|
2605 |
+
|
2606 |
+
public function addTo(La_SqlBuilder_WhereClause $whereClause) {
|
2607 |
+
foreach ($this->filters as $filter) {
|
2608 |
+
$filter->addTo($whereClause);
|
2609 |
+
}
|
2610 |
+
}
|
2611 |
+
|
2612 |
+
public function addSelectedFilterTo(La_SqlBuilder_WhereClause $whereClause, $filterCode, $columnCode = null) {
|
2613 |
+
if ($columnCode == null) {
|
2614 |
+
$columnCode = $filterCode;
|
2615 |
+
}
|
2616 |
+
foreach ($this->filters as $filter) {
|
2617 |
+
if ($filter->getCode() == $filterCode) {
|
2618 |
+
$oldCode = $filter->getCode();
|
2619 |
+
$filter->setCode($columnCode);
|
2620 |
+
$filter->addTo($whereClause);
|
2621 |
+
$filter->setCode($oldCode);
|
2622 |
+
}
|
2623 |
+
}
|
2624 |
+
}
|
2625 |
+
|
2626 |
+
/**
|
2627 |
+
* Returns first filter with specified code.
|
2628 |
+
* If filter with specified code does not exists null is returned.
|
2629 |
+
*
|
2630 |
+
* @param string $code
|
2631 |
+
* @return array<La_Filter>
|
2632 |
+
*/
|
2633 |
+
public function getFilter($code) {
|
2634 |
+
$filters = array();
|
2635 |
+
foreach ($this->filters as $filter) {
|
2636 |
+
if ($filter->getCode() == $code) {
|
2637 |
+
$filters[] = $filter;
|
2638 |
+
}
|
2639 |
+
}
|
2640 |
+
return $filters;
|
2641 |
+
}
|
2642 |
+
|
2643 |
+
public function isFilter($code) {
|
2644 |
+
foreach ($this->filters as $filter) {
|
2645 |
+
if ($filter->getCode() == $code) {
|
2646 |
+
return true;
|
2647 |
+
}
|
2648 |
+
}
|
2649 |
+
return false;
|
2650 |
+
}
|
2651 |
+
|
2652 |
+
public function getFilterValue($code) {
|
2653 |
+
$filters = $this->getFilter($code);
|
2654 |
+
if (count($filters) == 1) {
|
2655 |
+
return $filters[0]->getValue();
|
2656 |
+
}
|
2657 |
+
return "";
|
2658 |
+
}
|
2659 |
+
|
2660 |
+
public function matches(La_Data_Record $row) {
|
2661 |
+
foreach ($this->filters as $filter) {
|
2662 |
+
if (!$filter->matches($row)) {
|
2663 |
+
return false;
|
2664 |
+
}
|
2665 |
+
}
|
2666 |
+
return true;
|
2667 |
+
}
|
2668 |
+
|
2669 |
+
public function getSize() {
|
2670 |
+
return count($this->filters);
|
2671 |
+
}
|
2672 |
+
}
|
2673 |
+
|
2674 |
+
} //end La_Rpc_FilterCollection
|
2675 |
+
|
2676 |
+
if (!class_exists('La_Php', false)) {
|
2677 |
+
class La_Php {
|
2678 |
+
|
2679 |
+
/**
|
2680 |
+
* Check if function is enabled and exists in php
|
2681 |
+
*
|
2682 |
+
* @param $functionName
|
2683 |
+
* @return boolean Returns true if function exists and is enabled
|
2684 |
+
*/
|
2685 |
+
public static function isFunctionEnabled($functionName) {
|
2686 |
+
if (function_exists($functionName) && strstr(ini_get("disable_functions"), $functionName) === false) {
|
2687 |
+
return true;
|
2688 |
+
}
|
2689 |
+
return false;
|
2690 |
+
}
|
2691 |
+
|
2692 |
+
/**
|
2693 |
+
* Check if extension is loaded
|
2694 |
+
*
|
2695 |
+
* @param $extensionName
|
2696 |
+
* @return boolean Returns true if extension is loaded
|
2697 |
+
*/
|
2698 |
+
public static function isExtensionLoaded($extensionName) {
|
2699 |
+
return extension_loaded($extensionName);
|
2700 |
+
}
|
2701 |
+
|
2702 |
+
}
|
2703 |
+
|
2704 |
+
} //end La_Php
|
2705 |
+
|
2706 |
+
if (!class_exists('La_Rpc_ActionRequest', false)) {
|
2707 |
+
class La_Rpc_ActionRequest extends La_Rpc_Request {
|
2708 |
+
|
2709 |
+
/**
|
2710 |
+
* @return La_Rpc_Action
|
2711 |
+
*/
|
2712 |
+
public function getAction() {
|
2713 |
+
$action = new La_Rpc_Action(new La_Rpc_Params());
|
2714 |
+
$action->loadFromObject($this->getStdResponse());
|
2715 |
+
return $action;
|
2716 |
+
}
|
2717 |
+
}
|
2718 |
+
|
2719 |
+
|
2720 |
+
} //end La_Rpc_ActionRequest
|
2721 |
+
|
2722 |
+
if (!class_exists('La_Rpc_Action', false)) {
|
2723 |
+
class La_Rpc_Action extends La_Object implements La_Rpc_Serializable {
|
2724 |
+
private $errorMessage = "";
|
2725 |
+
private $infoMessage = "";
|
2726 |
+
private $successCount = 0;
|
2727 |
+
private $errorCount = 0;
|
2728 |
+
/**
|
2729 |
+
* @var La_Rpc_Params
|
2730 |
+
*/
|
2731 |
+
private $params;
|
2732 |
+
|
2733 |
+
public function __construct(La_Rpc_Params $params, $infoMessage = '', $errorMessage = '') {
|
2734 |
+
$this->params = $params;
|
2735 |
+
$this->infoMessage = $infoMessage;
|
2736 |
+
$this->errorMessage = $errorMessage;
|
2737 |
+
}
|
2738 |
+
|
2739 |
+
/**
|
2740 |
+
* @return Iterator
|
2741 |
+
*/
|
2742 |
+
public function getIds() {
|
2743 |
+
$massHandler = new La_Rpc_MassHandler($this->params);
|
2744 |
+
return $massHandler->getIds();
|
2745 |
+
}
|
2746 |
+
|
2747 |
+
public function getParam($name) {
|
2748 |
+
return $this->params->get($name);
|
2749 |
+
}
|
2750 |
+
|
2751 |
+
public function existsParam($name) {
|
2752 |
+
return $this->params->exists($name);
|
2753 |
+
}
|
2754 |
+
|
2755 |
+
/**
|
2756 |
+
* Parameter OK is mandatory
|
2757 |
+
* Parameter I and E is optional and only if there is value it is sent to client (empty values are not transferred)
|
2758 |
+
*
|
2759 |
+
* (non-PHPdoc)
|
2760 |
+
* @see include/Gpf/Rpc/La_Rpc_Serializable#toObject()
|
2761 |
+
*/
|
2762 |
+
public function toObject() {
|
2763 |
+
$response = new stdClass();
|
2764 |
+
$response->S = Gpf::YES;
|
2765 |
+
|
2766 |
+
if ($this->errorCount > 0) {
|
2767 |
+
$response->S = Gpf::NO;
|
2768 |
+
$response->E = $this->_($this->errorMessage, $this->errorCount);
|
2769 |
+
if (!strlen($response->E)) {
|
2770 |
+
unset($response->E);
|
2771 |
+
}
|
2772 |
+
}
|
2773 |
+
|
2774 |
+
if ($this->successCount > 0) {
|
2775 |
+
$response->I = $this->_($this->infoMessage, $this->successCount);
|
2776 |
+
if (!strlen($response->I)) {
|
2777 |
+
unset($response->I);
|
2778 |
+
}
|
2779 |
+
}
|
2780 |
+
|
2781 |
+
return $response;
|
2782 |
+
}
|
2783 |
+
|
2784 |
+
public function loadFromObject(stdClass $object) {
|
2785 |
+
$this->errorMessage = $object->errorMessage;
|
2786 |
+
$this->infoMessage = $object->infoMessage;
|
2787 |
+
|
2788 |
+
if($object->success == Gpf::NO) {
|
2789 |
+
$this->addError();
|
2790 |
+
}
|
2791 |
+
}
|
2792 |
+
|
2793 |
+
public function isError() {
|
2794 |
+
return $this->errorCount > 0;
|
2795 |
+
}
|
2796 |
+
|
2797 |
+
public function toText() {
|
2798 |
+
if ($this->isError()) {
|
2799 |
+
return $this->_($this->errorMessage, $this->errorCount);
|
2800 |
+
} else {
|
2801 |
+
return $this->_($this->infoMessage, $this->successCount);
|
2802 |
+
}
|
2803 |
+
}
|
2804 |
+
|
2805 |
+
public function setErrorMessage($message) {
|
2806 |
+
$this->errorMessage = $message;
|
2807 |
+
}
|
2808 |
+
|
2809 |
+
public function getErrorMessage() {
|
2810 |
+
return $this->errorMessage;
|
2811 |
+
}
|
2812 |
+
|
2813 |
+
public function setInfoMessage($message) {
|
2814 |
+
$this->infoMessage = $message;
|
2815 |
+
}
|
2816 |
+
|
2817 |
+
public function addOk() {
|
2818 |
+
$this->successCount++;
|
2819 |
+
}
|
2820 |
+
|
2821 |
+
public function addError() {
|
2822 |
+
$this->errorCount++;
|
2823 |
+
}
|
2824 |
+
|
2825 |
+
}
|
2826 |
+
|
2827 |
+
|
2828 |
+
} //end La_Rpc_Action
|
2829 |
+
|
2830 |
+
if (!class_exists('La_Rpc_Map', false)) {
|
2831 |
+
class La_Rpc_Map extends La_Object implements La_Rpc_Serializable {
|
2832 |
+
|
2833 |
+
function __construct(array $array){
|
2834 |
+
$this->array = $array;
|
2835 |
+
}
|
2836 |
+
|
2837 |
+
public function toObject() {
|
2838 |
+
return $this->array;
|
2839 |
+
}
|
2840 |
+
|
2841 |
+
public function toText() {
|
2842 |
+
return var_dump($this->array);
|
2843 |
+
}
|
2844 |
+
}
|
2845 |
+
|
2846 |
+
|
2847 |
+
} //end La_Rpc_Map
|
2848 |
+
|
2849 |
+
if (!class_exists('La_Log', false)) {
|
2850 |
+
class La_Log {
|
2851 |
+
const CRITICAL = 50;
|
2852 |
+
const ERROR = 40;
|
2853 |
+
const WARNING = 30;
|
2854 |
+
const INFO = 20;
|
2855 |
+
const DEBUG = 10;
|
2856 |
+
|
2857 |
+
/**
|
2858 |
+
* @var La_Log_Logger
|
2859 |
+
*/
|
2860 |
+
private static $logger;
|
2861 |
+
|
2862 |
+
/**
|
2863 |
+
* @return La_Log_Logger
|
2864 |
+
*/
|
2865 |
+
private static function getLogger() {
|
2866 |
+
if (self::$logger == null) {
|
2867 |
+
self::$logger = La_Log_Logger::getInstance();
|
2868 |
+
}
|
2869 |
+
return self::$logger;
|
2870 |
+
}
|
2871 |
+
|
2872 |
+
private function __construct() {
|
2873 |
+
}
|
2874 |
+
|
2875 |
+
public static function disableType($type) {
|
2876 |
+
self::getLogger()->disableType($type);
|
2877 |
+
}
|
2878 |
+
|
2879 |
+
public static function enableAllTypes() {
|
2880 |
+
self::getLogger()->enableAllTypes();
|
2881 |
+
}
|
2882 |
+
|
2883 |
+
/**
|
2884 |
+
* logs message
|
2885 |
+
*
|
2886 |
+
* @param string $message
|
2887 |
+
* @param string $logLevel
|
2888 |
+
* @param string $logGroup
|
2889 |
+
*/
|
2890 |
+
public static function log($message, $logLevel, $logGroup = null) {
|
2891 |
+
self::getLogger()->log($message, $logLevel, $logGroup);
|
2892 |
+
}
|
2893 |
+
|
2894 |
+
/**
|
2895 |
+
* logs debug message
|
2896 |
+
*
|
2897 |
+
* @param string $message
|
2898 |
+
* @param string $logGroup
|
2899 |
+
*/
|
2900 |
+
public static function debug($message, $logGroup = null) {
|
2901 |
+
self::getLogger()->debug($message, $logGroup);
|
2902 |
+
}
|
2903 |
+
|
2904 |
+
/**
|
2905 |
+
* logs info message
|
2906 |
+
*
|
2907 |
+
* @param string $message
|
2908 |
+
* @param string $logGroup
|
2909 |
+
*/
|
2910 |
+
public static function info($message, $logGroup = null) {
|
2911 |
+
self::getLogger()->info($message, $logGroup);
|
2912 |
+
}
|
2913 |
+
|
2914 |
+
/**
|
2915 |
+
* logs warning message
|
2916 |
+
*
|
2917 |
+
* @param string $message
|
2918 |
+
* @param string $logGroup
|
2919 |
+
*/
|
2920 |
+
public static function warning($message, $logGroup = null) {
|
2921 |
+
self::getLogger()->warning($message, $logGroup);
|
2922 |
+
}
|
2923 |
+
|
2924 |
+
/**
|
2925 |
+
* logs error message
|
2926 |
+
*
|
2927 |
+
* @param string $message
|
2928 |
+
* @param string $logGroup
|
2929 |
+
*/
|
2930 |
+
public static function error($message, $logGroup = null) {
|
2931 |
+
self::getLogger()->error($message, $logGroup);
|
2932 |
+
}
|
2933 |
+
|
2934 |
+
/**
|
2935 |
+
* logs critical error message
|
2936 |
+
*
|
2937 |
+
* @param string $message
|
2938 |
+
* @param string $logGroup
|
2939 |
+
*/
|
2940 |
+
public static function critical($message, $logGroup = null) {
|
2941 |
+
self::getLogger()->critical($message, $logGroup);
|
2942 |
+
}
|
2943 |
+
|
2944 |
+
/**
|
2945 |
+
* Attach new log system
|
2946 |
+
*
|
2947 |
+
* @param string $type
|
2948 |
+
* La_Log_LoggerDisplay::TYPE
|
2949 |
+
* La_Log_LoggerFile::TYPE
|
2950 |
+
* La_Log_LoggerDatabase::TYPE
|
2951 |
+
* @param string $logLevel
|
2952 |
+
* La_Log::CRITICAL
|
2953 |
+
* La_Log::ERROR
|
2954 |
+
* La_Log::WARNING
|
2955 |
+
* La_Log::INFO
|
2956 |
+
* La_Log::DEBUG
|
2957 |
+
* @return La_Log_LoggerBase
|
2958 |
+
*/
|
2959 |
+
public static function addLogger($type, $logLevel) {
|
2960 |
+
if($type instanceof La_Log_LoggerBase) {
|
2961 |
+
return self::getLogger()->addLogger($type, $logLevel);
|
2962 |
+
}
|
2963 |
+
return self::getLogger()->add($type, $logLevel);
|
2964 |
+
}
|
2965 |
+
|
2966 |
+
public static function removeAll() {
|
2967 |
+
self::getLogger()->removeAll();
|
2968 |
+
}
|
2969 |
+
}
|
2970 |
+
|
2971 |
+
} //end La_Log
|
2972 |
+
|
2973 |
+
if (!class_exists('La_Log_Logger', false)) {
|
2974 |
+
class La_Log_Logger extends La_Object {
|
2975 |
+
/**
|
2976 |
+
* @var array
|
2977 |
+
*/
|
2978 |
+
static private $instances = array();
|
2979 |
+
/**
|
2980 |
+
* @var array
|
2981 |
+
*/
|
2982 |
+
private $loggers = array();
|
2983 |
+
|
2984 |
+
/**
|
2985 |
+
* array of custom parameters
|
2986 |
+
*/
|
2987 |
+
private $customParameters = array();
|
2988 |
+
|
2989 |
+
private $disabledTypes = array();
|
2990 |
+
|
2991 |
+
private $group = null;
|
2992 |
+
private $type = null;
|
2993 |
+
private $logToDisplay = false;
|
2994 |
+
|
2995 |
+
/**
|
2996 |
+
* returns instance of logger class.
|
2997 |
+
* You can add instance name, if you want to have multiple independent instances of logger
|
2998 |
+
*
|
2999 |
+
* @param string $instanceName
|
3000 |
+
* @return La_Log_Logger
|
3001 |
+
*/
|
3002 |
+
public static function getInstance($instanceName = '_') {
|
3003 |
+
if($instanceName == '') {
|
3004 |
+
$instanceName = '_';
|
3005 |
+
}
|
3006 |
+
|
3007 |
+
if (!array_key_exists($instanceName, self::$instances)) {
|
3008 |
+
self::$instances[$instanceName] = new La_Log_Logger();
|
3009 |
+
}
|
3010 |
+
$instance = self::$instances[$instanceName];
|
3011 |
+
return $instance;
|
3012 |
+
}
|
3013 |
+
|
3014 |
+
public static function isLoggerInsert($sqlString) {
|
3015 |
+
return strpos($sqlString, 'INSERT INTO ' . La_Db_Table_Logs::getName()) !== false;
|
3016 |
+
}
|
3017 |
+
|
3018 |
+
/**
|
3019 |
+
* attachs new log system
|
3020 |
+
*
|
3021 |
+
* @param unknown_type $system
|
3022 |
+
* @return La_Log_LoggerBase
|
3023 |
+
*/
|
3024 |
+
public function add($type, $logLevel) {
|
3025 |
+
if($type == La_Log_LoggerDisplay::TYPE) {
|
3026 |
+
$this->logToDisplay = true;
|
3027 |
+
}
|
3028 |
+
return $this->addLogger($this->create($type), $logLevel);
|
3029 |
+
}
|
3030 |
+
|
3031 |
+
/**
|
3032 |
+
* Checks if logger with te specified type was already initialized
|
3033 |
+
*
|
3034 |
+
* @param unknown_type $type
|
3035 |
+
* @return unknown
|
3036 |
+
*/
|
3037 |
+
public function checkLoggerTypeExists($type) {
|
3038 |
+
if(array_key_exists($type, $this->loggers)) {
|
3039 |
+
return true;
|
3040 |
+
}
|
3041 |
+
|
3042 |
+
return false;
|
3043 |
+
}
|
3044 |
+
|
3045 |
+
/**
|
3046 |
+
* returns true if debugging writes log to display
|
3047 |
+
*
|
3048 |
+
* @return boolean
|
3049 |
+
*/
|
3050 |
+
public function isLogToDisplay() {
|
3051 |
+
return $this->logToDisplay;
|
3052 |
+
}
|
3053 |
+
|
3054 |
+
public function removeAll() {
|
3055 |
+
$this->loggers = array();
|
3056 |
+
$this->customParameters = array();
|
3057 |
+
$this->disabledTypes = array();
|
3058 |
+
$this->group = null;
|
3059 |
+
}
|
3060 |
+
|
3061 |
+
/**
|
3062 |
+
*
|
3063 |
+
* @param La_Log_LoggerBase $logger
|
3064 |
+
* @param int $logLevel
|
3065 |
+
* @return La_Log_LoggerBase
|
3066 |
+
*/
|
3067 |
+
public function addLogger(La_Log_LoggerBase $logger, $logLevel) {
|
3068 |
+
if(!$this->checkLoggerTypeExists($logger->getType())) {
|
3069 |
+
$logger->setLogLevel($logLevel);
|
3070 |
+
$this->loggers[$logger->getType()] = $logger;
|
3071 |
+
return $logger;
|
3072 |
+
} else {
|
3073 |
+
$ll = new La_Log_LoggerDatabase();
|
3074 |
+
$existingLogger = $this->loggers[$logger->getType()];
|
3075 |
+
if($existingLogger->getLogLevel() > $logLevel) {
|
3076 |
+
$existingLogger->setLogLevel($logLevel);
|
3077 |
+
}
|
3078 |
+
return $existingLogger;
|
3079 |
+
}
|
3080 |
+
}
|
3081 |
+
|
3082 |
+
public function getGroup() {
|
3083 |
+
return $this->group;
|
3084 |
+
}
|
3085 |
+
|
3086 |
+
public function setGroup($group = null) {
|
3087 |
+
$this->group = $group;
|
3088 |
+
if($group === null) {
|
3089 |
+
$this->group = La_Common_String::generateId(10);
|
3090 |
+
}
|
3091 |
+
}
|
3092 |
+
|
3093 |
+
public function setType($type) {
|
3094 |
+
$this->type = $type;
|
3095 |
+
}
|
3096 |
+
|
3097 |
+
/**
|
3098 |
+
* function sets custom parameter for the logger
|
3099 |
+
*
|
3100 |
+
* @param string $name
|
3101 |
+
* @param string $value
|
3102 |
+
*/
|
3103 |
+
public function setCustomParameter($name, $value) {
|
3104 |
+
$this->customParameters[$name] = $value;
|
3105 |
+
}
|
3106 |
+
|
3107 |
+
/**
|
3108 |
+
* returns custom parameter
|
3109 |
+
*
|
3110 |
+
* @param string $name
|
3111 |
+
* @return string
|
3112 |
+
*/
|
3113 |
+
public function getCustomParameter($name) {
|
3114 |
+
if(isset($this->customParameters[$name])) {
|
3115 |
+
return $this->customParameters[$name];
|
3116 |
+
}
|
3117 |
+
return '';
|
3118 |
+
}
|
3119 |
+
|
3120 |
+
/**
|
3121 |
+
* logs message
|
3122 |
+
*
|
3123 |
+
* @param string $message
|
3124 |
+
* @param string $logLevel
|
3125 |
+
* @param string $logGroup
|
3126 |
+
*/
|
3127 |
+
public function log($message, $logLevel, $logGroup = null) {
|
3128 |
+
$time = time();
|
3129 |
+
$backArr = debug_backtrace();
|
3130 |
+
$group = $logGroup;
|
3131 |
+
if($this->group !== null) {
|
3132 |
+
$group = $this->group;
|
3133 |
+
if($logGroup !== null) {
|
3134 |
+
$group .= ' ' . $logGroup;
|
3135 |
+
}
|
3136 |
+
}
|
3137 |
+
|
3138 |
+
$callingFile = $this->findLogFile();
|
3139 |
+
$file = $callingFile['file'];
|
3140 |
+
if(isset($callingFile['classVariables'])) {
|
3141 |
+
$file .= ' '.$callingFile['classVariables'];
|
3142 |
+
}
|
3143 |
+
$line = $callingFile['line'];
|
3144 |
+
|
3145 |
+
$ip = La_Http::getRemoteIp();
|
3146 |
+
if ($ip = '') {
|
3147 |
+
$ip = '127.0.0.1';
|
3148 |
+
}
|
3149 |
+
|
3150 |
+
foreach ($this->loggers as $logger) {
|
3151 |
+
if(!in_array($logger->getType(), $this->disabledTypes)) {
|
3152 |
+
$logger->logMessage($time, $message, $logLevel, $group, $ip, $file, $line, $this->type);
|
3153 |
+
}
|
3154 |
+
}
|
3155 |
+
}
|
3156 |
+
|
3157 |
+
/**
|
3158 |
+
* logs debug message
|
3159 |
+
*
|
3160 |
+
* @param string $message
|
3161 |
+
* @param string $logGroup
|
3162 |
+
*/
|
3163 |
+
public function debug($message, $logGroup = null) {
|
3164 |
+
$this->log($message, La_Log::DEBUG, $logGroup);
|
3165 |
+
}
|
3166 |
+
|
3167 |
+
/**
|
3168 |
+
* logs info message
|
3169 |
+
*
|
3170 |
+
* @param string $message
|
3171 |
+
* @param string $logGroup
|
3172 |
+
*/
|
3173 |
+
public function info($message, $logGroup = null) {
|
3174 |
+
$this->log($message, La_Log::INFO, $logGroup);
|
3175 |
+
}
|
3176 |
+
|
3177 |
+
/**
|
3178 |
+
* logs warning message
|
3179 |
+
*
|
3180 |
+
* @param string $message
|
3181 |
+
* @param string $logGroup
|
3182 |
+
*/
|
3183 |
+
public function warning($message, $logGroup = null) {
|
3184 |
+
$this->log($message, La_Log::WARNING, $logGroup);
|
3185 |
+
}
|
3186 |
+
|
3187 |
+
/**
|
3188 |
+
* logs error message
|
3189 |
+
*
|
3190 |
+
* @param string $message
|
3191 |
+
* @param string $logGroup
|
3192 |
+
*/
|
3193 |
+
public function error($message, $logGroup = null) {
|
3194 |
+
$this->log($message, La_Log::ERROR, $logGroup);
|
3195 |
+
}
|
3196 |
+
|
3197 |
+
/**
|
3198 |
+
* logs critical error message
|
3199 |
+
*
|
3200 |
+
* @param string $message
|
3201 |
+
* @param string $logGroup
|
3202 |
+
*/
|
3203 |
+
public function critical($message, $logGroup = null) {
|
3204 |
+
$this->log($message, La_Log::CRITICAL, $logGroup);
|
3205 |
+
}
|
3206 |
+
|
3207 |
+
public function disableType($type) {
|
3208 |
+
$this->disabledTypes[$type] =$type;
|
3209 |
+
}
|
3210 |
+
|
3211 |
+
public function enableAllTypes() {
|
3212 |
+
$this->disabledTypes = array();
|
3213 |
+
}
|
3214 |
+
|
3215 |
+
/**
|
3216 |
+
*
|
3217 |
+
* @return La_Log_LoggerBase
|
3218 |
+
*/
|
3219 |
+
private function create($type) {
|
3220 |
+
switch($type) {
|
3221 |
+
case La_Log_LoggerDisplay::TYPE:
|
3222 |
+
return new La_Log_LoggerDisplay();
|
3223 |
+
case La_Log_LoggerFile::TYPE:
|
3224 |
+
return new La_Log_LoggerFile();
|
3225 |
+
case La_Log_LoggerDatabase::TYPE:
|
3226 |
+
case 'db':
|
3227 |
+
return new La_Log_LoggerDatabase();
|
3228 |
+
}
|
3229 |
+
throw new La_Log_Exception("Log system '$type' does not exist");
|
3230 |
+
}
|
3231 |
+
|
3232 |
+
private function findLogFile() {
|
3233 |
+
$calls = debug_backtrace();
|
3234 |
+
|
3235 |
+
$foundObject = null;
|
3236 |
+
|
3237 |
+
// special handling for sql benchmarks
|
3238 |
+
if($this->sqlBenchmarkFound($calls)) {
|
3239 |
+
$foundObject = $this->findFileBySqlBenchmark();
|
3240 |
+
}
|
3241 |
+
|
3242 |
+
if($foundObject == null) {
|
3243 |
+
$foundObject = $this->findFileByCallingMethod($calls);
|
3244 |
+
}
|
3245 |
+
if($foundObject == null) {
|
3246 |
+
$foundObject = $this->findLatestObjectBeforeString("Logger.class.php");
|
3247 |
+
}
|
3248 |
+
if($foundObject == null) {
|
3249 |
+
$last = count($calls);
|
3250 |
+
$last -= 1;
|
3251 |
+
if($last <0) {
|
3252 |
+
$last = 0;
|
3253 |
+
}
|
3254 |
+
|
3255 |
+
$foundObject = $calls[$last];
|
3256 |
+
}
|
3257 |
+
|
3258 |
+
return $foundObject;
|
3259 |
+
}
|
3260 |
+
|
3261 |
+
private function sqlBenchmarkFound($calls) {
|
3262 |
+
foreach($calls as $obj) {
|
3263 |
+
if(isset($obj['function']) && $obj['function'] == "sqlBenchmarkEnd") {
|
3264 |
+
return true;
|
3265 |
+
}
|
3266 |
+
}
|
3267 |
+
return false;
|
3268 |
+
}
|
3269 |
+
|
3270 |
+
private function findFileBySqlBenchmark() {
|
3271 |
+
$foundFile = $this->findLatestObjectBeforeString("DbEngine");
|
3272 |
+
if($foundFile != null && is_object($foundFile['object'])) {
|
3273 |
+
$foundFile['classVariables'] = $this->getObjectVariables($foundFile['object']);
|
3274 |
+
}
|
3275 |
+
return $foundFile;
|
3276 |
+
}
|
3277 |
+
|
3278 |
+
private function getObjectVariables($object) {
|
3279 |
+
if(is_object($object)) {
|
3280 |
+
$class = get_class($object);
|
3281 |
+
$methods = get_class_methods($class);
|
3282 |
+
if(in_array("__toString", $methods)) {
|
3283 |
+
return $object->__toString();
|
3284 |
+
}
|
3285 |
+
}
|
3286 |
+
return '';
|
3287 |
+
}
|
3288 |
+
|
3289 |
+
private function findFileByCallingMethod($calls) {
|
3290 |
+
$functionNames = array('debug', 'info', 'warning', 'error', 'critical', 'log');
|
3291 |
+
$foundObject = null;
|
3292 |
+
foreach($functionNames as $name) {
|
3293 |
+
$foundObject = $this->findCallingFile($calls, $name);
|
3294 |
+
if($foundObject != null) {
|
3295 |
+
return $foundObject;
|
3296 |
+
}
|
3297 |
+
}
|
3298 |
+
|
3299 |
+
return null;
|
3300 |
+
}
|
3301 |
+
|
3302 |
+
private function findCallingFile($calls, $functionName) {
|
3303 |
+
foreach($calls as $obj) {
|
3304 |
+
if(isset($obj['function']) && $obj['function'] == $functionName) {
|
3305 |
+
return $obj;
|
3306 |
+
}
|
3307 |
+
}
|
3308 |
+
|
3309 |
+
return null;
|
3310 |
+
}
|
3311 |
+
|
3312 |
+
private function findLatestObjectBeforeString($text) {
|
3313 |
+
$callsReversed = array_reverse( debug_backtrace() );
|
3314 |
+
|
3315 |
+
$lastObject = null;
|
3316 |
+
foreach($callsReversed as $obj) {
|
3317 |
+
if(!isset($obj['file'])) {
|
3318 |
+
continue;
|
3319 |
+
}
|
3320 |
+
$pos = strpos($obj['file'], $text);
|
3321 |
+
if($pos !== false && $lastObject != null) {
|
3322 |
+
return $lastObject;
|
3323 |
+
}
|
3324 |
+
$lastObject = $obj;
|
3325 |
+
}
|
3326 |
+
return null;
|
3327 |
+
}
|
3328 |
+
}
|
3329 |
+
|
3330 |
+
} //end La_Log_Logger
|
3331 |
+
|
3332 |
+
if (!class_exists('La_Api_IncompatibleVersionException', false)) {
|
3333 |
+
class La_Api_IncompatibleVersionException extends Exception {
|
3334 |
+
|
3335 |
+
private $apiLink;
|
3336 |
+
|
3337 |
+
public function __construct($url) {
|
3338 |
+
$this->apiLink = $url. '?C=La_Api_DownloadAPI&M=download&FormRequest=Y&FormResponse=Y';
|
3339 |
+
parent::__construct('Version of API not corresponds to the Application version. Please <a href="' . $this->apiLink . '">download latest version of API</a>.', 0);
|
3340 |
+
}
|
3341 |
+
|
3342 |
+
public function getApiDownloadLink() {
|
3343 |
+
return $this->apiLink;
|
3344 |
+
}
|
3345 |
+
|
3346 |
+
}
|
3347 |
+
|
3348 |
+
} //end La_Api_IncompatibleVersionException
|
3349 |
+
|
3350 |
+
if (!class_exists('La_Api_Session', false)) {
|
3351 |
+
class La_Api_Session extends La_Object {
|
3352 |
+
const MERCHANT = 'M';
|
3353 |
+
const AFFILIATE = 'A';
|
3354 |
+
|
3355 |
+
private $url;
|
3356 |
+
private $sessionId = '';
|
3357 |
+
private $debug = false;
|
3358 |
+
private $message = '';
|
3359 |
+
private $roleType = '';
|
3360 |
+
|
3361 |
+
public function __construct($url) {
|
3362 |
+
$this->url = $url;
|
3363 |
+
}
|
3364 |
+
/**
|
3365 |
+
*
|
3366 |
+
* @param $username
|
3367 |
+
* @param $password
|
3368 |
+
* @param $roleType La_Api_Session::MERCHANT or La_Api_Session::AFFILIATE
|
3369 |
+
* @param $languageCode language code (e.g. en-US, de-DE, sk, cz, du, ...)
|
3370 |
+
* @return boolean true if user was sucesfully logged
|
3371 |
+
* @throws La_Api_IncompatibleVersionException
|
3372 |
+
*/
|
3373 |
+
public function login($username, $password, $roleType = self::MERCHANT, $languageCode = null) {
|
3374 |
+
$request = new La_Rpc_FormRequest("La_Api_AuthService", "authenticate");
|
3375 |
+
$request->setUrl($this->url);
|
3376 |
+
$request->setField("username", $username);
|
3377 |
+
$request->setField("password", $password);
|
3378 |
+
$request->setField("roleType", $roleType);
|
3379 |
+
$request->setField('apiVersion', self::getAPIVersion());
|
3380 |
+
if($languageCode != null) {
|
3381 |
+
$request->setField("language", $languageCode);
|
3382 |
+
}
|
3383 |
+
|
3384 |
+
$this->roleType = $roleType;
|
3385 |
+
|
3386 |
+
try {
|
3387 |
+
$request->sendNow();
|
3388 |
+
} catch(Exception $e) {
|
3389 |
+
$this->setMessage("Connection error: ".$e->getMessage());
|
3390 |
+
return false;
|
3391 |
+
}
|
3392 |
+
|
3393 |
+
$form = $request->getForm();
|
3394 |
+
$this->checkApiVersion($form);
|
3395 |
+
|
3396 |
+
$this->message = $form->getInfoMessage();
|
3397 |
+
|
3398 |
+
if($form->isSuccessful() && $form->existsField("S")) {
|
3399 |
+
$this->sessionId = $form->getFieldValue("S");
|
3400 |
+
$this->setMessage($form->getInfoMessage());
|
3401 |
+
return true;
|
3402 |
+
}
|
3403 |
+
|
3404 |
+
$this->setMessage($form->getErrorMessage());
|
3405 |
+
return false;
|
3406 |
+
}
|
3407 |
+
|
3408 |
+
/**
|
3409 |
+
* Get version of installed application
|
3410 |
+
*
|
3411 |
+
* @return string version of installed application
|
3412 |
+
*/
|
3413 |
+
public function getAppVersion() {
|
3414 |
+
$request = new La_Rpc_FormRequest("La_Api_AuthService", "getAppVersion");
|
3415 |
+
$request->setUrl($this->url);
|
3416 |
+
|
3417 |
+
try {
|
3418 |
+
$request->sendNow();
|
3419 |
+
} catch(Exception $e) {
|
3420 |
+
$this->setMessage("Connection error: ".$e->getMessage());
|
3421 |
+
return false;
|
3422 |
+
}
|
3423 |
+
|
3424 |
+
$form = $request->getForm();
|
3425 |
+
return $form->getFieldValue('version');
|
3426 |
+
}
|
3427 |
+
|
3428 |
+
|
3429 |
+
public function getMessage() {
|
3430 |
+
return $this->message;
|
3431 |
+
}
|
3432 |
+
|
3433 |
+
private function setMessage($msg) {
|
3434 |
+
$this->message = $msg;
|
3435 |
+
}
|
3436 |
+
|
3437 |
+
public function getDebug() {
|
3438 |
+
return $this->debug;
|
3439 |
+
}
|
3440 |
+
|
3441 |
+
public function setDebug($debug = true) {
|
3442 |
+
$this->debug = $debug;
|
3443 |
+
}
|
3444 |
+
|
3445 |
+
public function getSessionId() {
|
3446 |
+
return $this->sessionId;
|
3447 |
+
}
|
3448 |
+
|
3449 |
+
public function setSessionId($id) {
|
3450 |
+
$this->sessionId = $id;
|
3451 |
+
}
|
3452 |
+
|
3453 |
+
public function getRoleType() {
|
3454 |
+
return $this->roleType;
|
3455 |
+
}
|
3456 |
+
|
3457 |
+
public function getUrl() {
|
3458 |
+
return $this->url;
|
3459 |
+
}
|
3460 |
+
|
3461 |
+
public function getUrlWithSessionInfo($url) {
|
3462 |
+
if (strpos($url, '?') === false) {
|
3463 |
+
return $url . '?S=' . $this->getSessionId();
|
3464 |
+
}
|
3465 |
+
return $url . '&S=' . $this->getSessionId();
|
3466 |
+
}
|
3467 |
+
|
3468 |
+
/**
|
3469 |
+
* @param $latestVersion
|
3470 |
+
* @throws La_Api_IncompatibleVersionException
|
3471 |
+
*/
|
3472 |
+
private function checkApiVersion(La_Rpc_Form $form) {
|
3473 |
+
if ($form->getFieldValue('correspondsApi') === Gpf::NO) {
|
3474 |
+
throw new La_Api_IncompatibleVersionException($this->url);
|
3475 |
+
}
|
3476 |
+
}
|
3477 |
+
|
3478 |
+
/**
|
3479 |
+
* @return String
|
3480 |
+
*/
|
3481 |
+
public static function getAPIVersion($fileName = __FILE__) {
|
3482 |
+
$fileHandler = fopen($fileName, 'r');
|
3483 |
+
fseek($fileHandler, -6 -32, SEEK_END);
|
3484 |
+
$hash = fgets($fileHandler);
|
3485 |
+
return substr($hash, 0, -1);
|
3486 |
+
}
|
3487 |
+
}
|
3488 |
+
|
3489 |
+
} //end La_Api_Session
|
3490 |
+
|
3491 |
+
if (!class_exists('La_Rpc_Json', false)) {
|
3492 |
+
class La_Rpc_Json implements La_Rpc_DataEncoder, La_Rpc_DataDecoder {
|
3493 |
+
/**
|
3494 |
+
* Marker constant for Services_JSON::decode(), used to flag stack state
|
3495 |
+
*/
|
3496 |
+
const SERVICES_JSON_SLICE = 1;
|
3497 |
+
|
3498 |
+
/**
|
3499 |
+
* Marker constant for Services_JSON::decode(), used to flag stack state
|
3500 |
+
*/
|
3501 |
+
const SERVICES_JSON_IN_STR = 2;
|
3502 |
+
|
3503 |
+
/**
|
3504 |
+
* Marker constant for Services_JSON::decode(), used to flag stack state
|
3505 |
+
*/
|
3506 |
+
const SERVICES_JSON_IN_ARR = 3;
|
3507 |
+
|
3508 |
+
/**
|
3509 |
+
* Marker constant for Services_JSON::decode(), used to flag stack state
|
3510 |
+
*/
|
3511 |
+
const SERVICES_JSON_IN_OBJ = 4;
|
3512 |
+
|
3513 |
+
/**
|
3514 |
+
* Marker constant for Services_JSON::decode(), used to flag stack state
|
3515 |
+
*/
|
3516 |
+
const SERVICES_JSON_IN_CMT = 5;
|
3517 |
+
|
3518 |
+
/**
|
3519 |
+
* Behavior switch for Services_JSON::decode()
|
3520 |
+
*/
|
3521 |
+
const SERVICES_JSON_LOOSE_TYPE = 16;
|
3522 |
+
|
3523 |
+
/**
|
3524 |
+
* Behavior switch for Services_JSON::decode()
|
3525 |
+
*/
|
3526 |
+
const SERVICES_JSON_SUPPRESS_ERRORS = 32;
|
3527 |
+
|
3528 |
+
/**
|
3529 |
+
* constructs a new JSON instance
|
3530 |
+
*
|
3531 |
+
* @param int $use object behavior flags; combine with boolean-OR
|
3532 |
+
*
|
3533 |
+
* possible values:
|
3534 |
+
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
|
3535 |
+
* "{...}" syntax creates associative arrays
|
3536 |
+
* instead of objects in decode().
|
3537 |
+
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
|
3538 |
+
* Values which can't be encoded (e.g. resources)
|
3539 |
+
* appear as NULL instead of throwing errors.
|
3540 |
+
* By default, a deeply-nested resource will
|
3541 |
+
* bubble up with an error, so all return values
|
3542 |
+
* from encode() should be checked with isError()
|
3543 |
+
*/
|
3544 |
+
function __construct($use = 0)
|
3545 |
+
{
|
3546 |
+
$this->use = $use;
|
3547 |
+
}
|
3548 |
+
|
3549 |
+
/**
|
3550 |
+
* @var La_Rpc_Json
|
3551 |
+
*/
|
3552 |
+
private static $instance;
|
3553 |
+
|
3554 |
+
/**
|
3555 |
+
*
|
3556 |
+
* @return La_Rpc_Json
|
3557 |
+
*/
|
3558 |
+
private function getInstance() {
|
3559 |
+
if (self::$instance === null) {
|
3560 |
+
self::$instance = new self;
|
3561 |
+
}
|
3562 |
+
return self::$instance;
|
3563 |
+
}
|
3564 |
+
|
3565 |
+
public static function encodeStatic($var) {
|
3566 |
+
return self::getInstance()->encode($var);
|
3567 |
+
}
|
3568 |
+
|
3569 |
+
public static function decodeStatic($var) {
|
3570 |
+
return self::getInstance()->decode($var);
|
3571 |
+
}
|
3572 |
+
|
3573 |
+
/**
|
3574 |
+
* convert a string from one UTF-16 char to one UTF-8 char
|
3575 |
+
*
|
3576 |
+
* Normally should be handled by mb_convert_encoding, but
|
3577 |
+
* provides a slower PHP-only method for installations
|
3578 |
+
* that lack the multibye string extension.
|
3579 |
+
*
|
3580 |
+
* @param string $utf16 UTF-16 character
|
3581 |
+
* @return string UTF-8 character
|
3582 |
+
* @access private
|
3583 |
+
*/
|
3584 |
+
function utf162utf8($utf16)
|
3585 |
+
{
|
3586 |
+
// oh please oh please oh please oh please oh please
|
3587 |
+
if(La_Php::isFunctionEnabled('mb_convert_encoding')) {
|
3588 |
+
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
|
3589 |
+
}
|
3590 |
+
|
3591 |
+
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
|
3592 |
+
|
3593 |
+
switch(true) {
|
3594 |
+
case ((0x7F & $bytes) == $bytes):
|
3595 |
+
// this case should never be reached, because we are in ASCII range
|
3596 |
+
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3597 |
+
return chr(0x7F & $bytes);
|
3598 |
+
|
3599 |
+
case (0x07FF & $bytes) == $bytes:
|
3600 |
+
// return a 2-byte UTF-8 character
|
3601 |
+
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3602 |
+
return chr(0xC0 | (($bytes >> 6) & 0x1F))
|
3603 |
+
. chr(0x80 | ($bytes & 0x3F));
|
3604 |
+
|
3605 |
+
case (0xFFFF & $bytes) == $bytes:
|
3606 |
+
// return a 3-byte UTF-8 character
|
3607 |
+
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3608 |
+
return chr(0xE0 | (($bytes >> 12) & 0x0F))
|
3609 |
+
. chr(0x80 | (($bytes >> 6) & 0x3F))
|
3610 |
+
. chr(0x80 | ($bytes & 0x3F));
|
3611 |
+
}
|
3612 |
+
|
3613 |
+
// ignoring UTF-32 for now, sorry
|
3614 |
+
return '';
|
3615 |
+
}
|
3616 |
+
|
3617 |
+
/**
|
3618 |
+
* convert a string from one UTF-8 char to one UTF-16 char
|
3619 |
+
*
|
3620 |
+
* Normally should be handled by mb_convert_encoding, but
|
3621 |
+
* provides a slower PHP-only method for installations
|
3622 |
+
* that lack the multibye string extension.
|
3623 |
+
*
|
3624 |
+
* @param string $utf8 UTF-8 character
|
3625 |
+
* @return string UTF-16 character
|
3626 |
+
* @access private
|
3627 |
+
*/
|
3628 |
+
function utf82utf16($utf8)
|
3629 |
+
{
|
3630 |
+
// oh please oh please oh please oh please oh please
|
3631 |
+
if(La_Php::isFunctionEnabled('mb_convert_encoding')) {
|
3632 |
+
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
|
3633 |
+
}
|
3634 |
+
|
3635 |
+
switch(strlen($utf8)) {
|
3636 |
+
case 1:
|
3637 |
+
// this case should never be reached, because we are in ASCII range
|
3638 |
+
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3639 |
+
return $utf8;
|
3640 |
+
|
3641 |
+
case 2:
|
3642 |
+
// return a UTF-16 character from a 2-byte UTF-8 char
|
3643 |
+
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3644 |
+
return chr(0x07 & (ord($utf8{0}) >> 2))
|
3645 |
+
. chr((0xC0 & (ord($utf8{0}) << 6))
|
3646 |
+
| (0x3F & ord($utf8{1})));
|
3647 |
+
|
3648 |
+
case 3:
|
3649 |
+
// return a UTF-16 character from a 3-byte UTF-8 char
|
3650 |
+
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3651 |
+
return chr((0xF0 & (ord($utf8{0}) << 4))
|
3652 |
+
| (0x0F & (ord($utf8{1}) >> 2)))
|
3653 |
+
. chr((0xC0 & (ord($utf8{1}) << 6))
|
3654 |
+
| (0x7F & ord($utf8{2})));
|
3655 |
+
}
|
3656 |
+
|
3657 |
+
// ignoring UTF-32 for now, sorry
|
3658 |
+
return '';
|
3659 |
+
}
|
3660 |
+
|
3661 |
+
public function encodeResponse(La_Rpc_Serializable $response) {
|
3662 |
+
return $this->encode($response->toObject());
|
3663 |
+
}
|
3664 |
+
|
3665 |
+
/**
|
3666 |
+
* encodes an arbitrary variable into JSON format
|
3667 |
+
*
|
3668 |
+
* @param mixed $var any number, boolean, string, array, or object to be encoded.
|
3669 |
+
* see argument 1 to Services_JSON() above for array-parsing behavior.
|
3670 |
+
* if var is a strng, note that encode() always expects it
|
3671 |
+
* to be in ASCII or UTF-8 format!
|
3672 |
+
*
|
3673 |
+
* @return mixed JSON string representation of input var or an error if a problem occurs
|
3674 |
+
* @access public
|
3675 |
+
*/
|
3676 |
+
public function encode($var) {
|
3677 |
+
if ($this->isJsonEncodeEnabled()) {
|
3678 |
+
return @json_encode($var);
|
3679 |
+
}
|
3680 |
+
switch (gettype($var)) {
|
3681 |
+
case 'boolean':
|
3682 |
+
return $var ? 'true' : 'false';
|
3683 |
+
|
3684 |
+
case 'NULL':
|
3685 |
+
return 'null';
|
3686 |
+
|
3687 |
+
case 'integer':
|
3688 |
+
return (int) $var;
|
3689 |
+
|
3690 |
+
case 'double':
|
3691 |
+
case 'float':
|
3692 |
+
return (float) $var;
|
3693 |
+
|
3694 |
+
case 'string':
|
3695 |
+
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
|
3696 |
+
$ascii = '';
|
3697 |
+
$strlen_var = strlen($var);
|
3698 |
+
|
3699 |
+
/*
|
3700 |
+
* Iterate over every character in the string,
|
3701 |
+
* escaping with a slash or encoding to UTF-8 where necessary
|
3702 |
+
*/
|
3703 |
+
for ($c = 0; $c < $strlen_var; ++$c) {
|
3704 |
+
|
3705 |
+
$ord_var_c = ord($var{$c});
|
3706 |
+
|
3707 |
+
switch (true) {
|
3708 |
+
case $ord_var_c == 0x08:
|
3709 |
+
$ascii .= '\b';
|
3710 |
+
break;
|
3711 |
+
case $ord_var_c == 0x09:
|
3712 |
+
$ascii .= '\t';
|
3713 |
+
break;
|
3714 |
+
case $ord_var_c == 0x0A:
|
3715 |
+
$ascii .= '\n';
|
3716 |
+
break;
|
3717 |
+
case $ord_var_c == 0x0C:
|
3718 |
+
$ascii .= '\f';
|
3719 |
+
break;
|
3720 |
+
case $ord_var_c == 0x0D:
|
3721 |
+
$ascii .= '\r';
|
3722 |
+
break;
|
3723 |
+
|
3724 |
+
case $ord_var_c == 0x22:
|
3725 |
+
case $ord_var_c == 0x2F:
|
3726 |
+
case $ord_var_c == 0x5C:
|
3727 |
+
// double quote, slash, slosh
|
3728 |
+
$ascii .= '\\'.$var{$c};
|
3729 |
+
break;
|
3730 |
+
|
3731 |
+
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
|
3732 |
+
// characters U-00000000 - U-0000007F (same as ASCII)
|
3733 |
+
$ascii .= $var{$c};
|
3734 |
+
break;
|
3735 |
+
|
3736 |
+
case (($ord_var_c & 0xE0) == 0xC0):
|
3737 |
+
// characters U-00000080 - U-000007FF, mask 1 1 0 X X X X X
|
3738 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3739 |
+
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
|
3740 |
+
$c += 1;
|
3741 |
+
$utf16 = $this->utf82utf16($char);
|
3742 |
+
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
3743 |
+
break;
|
3744 |
+
|
3745 |
+
case (($ord_var_c & 0xF0) == 0xE0):
|
3746 |
+
// characters U-00000800 - U-0000FFFF, mask 1 1 1 0 X X X X
|
3747 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3748 |
+
$char = pack('C*', $ord_var_c,
|
3749 |
+
ord($var{$c + 1}),
|
3750 |
+
ord($var{$c + 2}));
|
3751 |
+
$c += 2;
|
3752 |
+
$utf16 = $this->utf82utf16($char);
|
3753 |
+
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
3754 |
+
break;
|
3755 |
+
|
3756 |
+
case (($ord_var_c & 0xF8) == 0xF0):
|
3757 |
+
// characters U-00010000 - U-001FFFFF, mask 1 1 1 1 0 X X X
|
3758 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3759 |
+
$char = pack('C*', $ord_var_c,
|
3760 |
+
ord($var{$c + 1}),
|
3761 |
+
ord($var{$c + 2}),
|
3762 |
+
ord($var{$c + 3}));
|
3763 |
+
$c += 3;
|
3764 |
+
$utf16 = $this->utf82utf16($char);
|
3765 |
+
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
3766 |
+
break;
|
3767 |
+
|
3768 |
+
case (($ord_var_c & 0xFC) == 0xF8):
|
3769 |
+
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
3770 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3771 |
+
$char = pack('C*', $ord_var_c,
|
3772 |
+
ord($var{$c + 1}),
|
3773 |
+
ord($var{$c + 2}),
|
3774 |
+
ord($var{$c + 3}),
|
3775 |
+
ord($var{$c + 4}));
|
3776 |
+
$c += 4;
|
3777 |
+
$utf16 = $this->utf82utf16($char);
|
3778 |
+
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
3779 |
+
break;
|
3780 |
+
|
3781 |
+
case (($ord_var_c & 0xFE) == 0xFC):
|
3782 |
+
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
3783 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
3784 |
+
$char = pack('C*', $ord_var_c,
|
3785 |
+
ord($var{$c + 1}),
|
3786 |
+
ord($var{$c + 2}),
|
3787 |
+
ord($var{$c + 3}),
|
3788 |
+
ord($var{$c + 4}),
|
3789 |
+
ord($var{$c + 5}));
|
3790 |
+
$c += 5;
|
3791 |
+
$utf16 = $this->utf82utf16($char);
|
3792 |
+
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
3793 |
+
break;
|
3794 |
+
}
|
3795 |
+
}
|
3796 |
+
|
3797 |
+
return '"'.$ascii.'"';
|
3798 |
+
|
3799 |
+
case 'array':
|
3800 |
+
/*
|
3801 |
+
* As per JSON spec if any array key is not an integer
|
3802 |
+
* we must treat the the whole array as an object. We
|
3803 |
+
* also try to catch a sparsely populated associative
|
3804 |
+
* array with numeric keys here because some JS engines
|
3805 |
+
* will create an array with empty indexes up to
|
3806 |
+
* max_index which can cause memory issues and because
|
3807 |
+
* the keys, which may be relevant, will be remapped
|
3808 |
+
* otherwise.
|
3809 |
+
*
|
3810 |
+
* As per the ECMA and JSON specification an object may
|
3811 |
+
* have any string as a property. Unfortunately due to
|
3812 |
+
* a hole in the ECMA specification if the key is a
|
3813 |
+
* ECMA reserved word or starts with a digit the
|
3814 |
+
* parameter is only accessible using ECMAScript's
|
3815 |
+
* bracket notation.
|
3816 |
+
*/
|
3817 |
+
|
3818 |
+
// treat as a JSON object
|
3819 |
+
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
|
3820 |
+
$properties = array_map(array($this, 'name_value'), array_keys($var), array_values($var));
|
3821 |
+
|
3822 |
+
foreach($properties as $property) {
|
3823 |
+
if(La_Rpc_Json::isError($property)) {
|
3824 |
+
return $property;
|
3825 |
+
}
|
3826 |
+
}
|
3827 |
+
|
3828 |
+
return '{' . join(',', $properties) . '}';
|
3829 |
+
}
|
3830 |
+
|
3831 |
+
// treat it like a regular array
|
3832 |
+
$elements = array_map(array($this, 'encode'), $var);
|
3833 |
+
|
3834 |
+
foreach($elements as $element) {
|
3835 |
+
if(La_Rpc_Json::isError($element)) {
|
3836 |
+
return $element;
|
3837 |
+
}
|
3838 |
+
}
|
3839 |
+
|
3840 |
+
return '[' . join(',', $elements) . ']';
|
3841 |
+
|
3842 |
+
case 'object':
|
3843 |
+
$vars = get_object_vars($var);
|
3844 |
+
|
3845 |
+
$properties = array_map(array($this, 'name_value'),
|
3846 |
+
array_keys($vars),
|
3847 |
+
array_values($vars));
|
3848 |
+
|
3849 |
+
foreach($properties as $property) {
|
3850 |
+
if(La_Rpc_Json::isError($property)) {
|
3851 |
+
return $property;
|
3852 |
+
}
|
3853 |
+
}
|
3854 |
+
|
3855 |
+
return '{' . join(',', $properties) . '}';
|
3856 |
+
|
3857 |
+
default:
|
3858 |
+
if ($this->use & self::SERVICES_JSON_SUPPRESS_ERRORS) {
|
3859 |
+
return 'null';
|
3860 |
+
}
|
3861 |
+
return new La_Rpc_Json_Error(gettype($var)." can not be encoded as JSON string");
|
3862 |
+
}
|
3863 |
+
}
|
3864 |
+
|
3865 |
+
/**
|
3866 |
+
* array-walking function for use in generating JSON-formatted name-value pairs
|
3867 |
+
*
|
3868 |
+
* @param string $name name of key to use
|
3869 |
+
* @param mixed $value reference to an array element to be encoded
|
3870 |
+
*
|
3871 |
+
* @return string JSON-formatted name-value pair, like '"name":value'
|
3872 |
+
* @access private
|
3873 |
+
*/
|
3874 |
+
function name_value($name, $value)
|
3875 |
+
{
|
3876 |
+
$encoded_value = $this->encode($value);
|
3877 |
+
|
3878 |
+
if(La_Rpc_Json::isError($encoded_value)) {
|
3879 |
+
return $encoded_value;
|
3880 |
+
}
|
3881 |
+
|
3882 |
+
return $this->encode(strval($name)) . ':' . $encoded_value;
|
3883 |
+
}
|
3884 |
+
|
3885 |
+
/**
|
3886 |
+
* reduce a string by removing leading and trailing comments and whitespace
|
3887 |
+
*
|
3888 |
+
* @param $str string string value to strip of comments and whitespace
|
3889 |
+
*
|
3890 |
+
* @return string string value stripped of comments and whitespace
|
3891 |
+
* @access private
|
3892 |
+
*/
|
3893 |
+
function reduce_string($str)
|
3894 |
+
{
|
3895 |
+
$str = preg_replace(array(
|
3896 |
+
|
3897 |
+
// eliminate single line comments in '// ...' form
|
3898 |
+
'#^\s*//(.+)$#m',
|
3899 |
+
|
3900 |
+
// eliminate multi-line comments in '/* ... */' form, at start of string
|
3901 |
+
'#^\s*/\*(.+)\*/#Us',
|
3902 |
+
|
3903 |
+
// eliminate multi-line comments in '/* ... */' form, at end of string
|
3904 |
+
'#/\*(.+)\*/\s*$#Us'
|
3905 |
+
|
3906 |
+
), '', $str);
|
3907 |
+
|
3908 |
+
// eliminate extraneous space
|
3909 |
+
return trim($str);
|
3910 |
+
}
|
3911 |
+
|
3912 |
+
/**
|
3913 |
+
* decodes a JSON string into appropriate variable
|
3914 |
+
*
|
3915 |
+
* @param string $str JSON-formatted string
|
3916 |
+
*
|
3917 |
+
* @return mixed number, boolean, string, array, or object
|
3918 |
+
* corresponding to given JSON input string.
|
3919 |
+
* See argument 1 to Services_JSON() above for object-output behavior.
|
3920 |
+
* Note that decode() always returns strings
|
3921 |
+
* in ASCII or UTF-8 format!
|
3922 |
+
* @access public
|
3923 |
+
*/
|
3924 |
+
function decode($str)
|
3925 |
+
{
|
3926 |
+
if ($this->isJsonDecodeEnabled()) {
|
3927 |
+
return json_decode($str);
|
3928 |
+
}
|
3929 |
+
|
3930 |
+
$str = $this->reduce_string($str);
|
3931 |
+
|
3932 |
+
switch (strtolower($str)) {
|
3933 |
+
case 'true':
|
3934 |
+
return true;
|
3935 |
+
|
3936 |
+
case 'false':
|
3937 |
+
return false;
|
3938 |
+
|
3939 |
+
case 'null':
|
3940 |
+
return null;
|
3941 |
+
|
3942 |
+
default:
|
3943 |
+
$m = array();
|
3944 |
+
|
3945 |
+
if (is_numeric($str)) {
|
3946 |
+
// Lookie-loo, it's a number
|
3947 |
+
|
3948 |
+
// This would work on its own, but I'm trying to be
|
3949 |
+
// good about returning integers where appropriate:
|
3950 |
+
// return (float)$str;
|
3951 |
+
|
3952 |
+
// Return float or int, as appropriate
|
3953 |
+
return ((float)$str == (integer)$str)
|
3954 |
+
? (integer)$str
|
3955 |
+
: (float)$str;
|
3956 |
+
|
3957 |
+
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
|
3958 |
+
// STRINGS RETURNED IN UTF-8 FORMAT
|
3959 |
+
$delim = substr($str, 0, 1);
|
3960 |
+
$chrs = substr($str, 1, -1);
|
3961 |
+
$utf8 = '';
|
3962 |
+
$strlen_chrs = strlen($chrs);
|
3963 |
+
|
3964 |
+
for ($c = 0; $c < $strlen_chrs; ++$c) {
|
3965 |
+
|
3966 |
+
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
3967 |
+
$ord_chrs_c = ord($chrs{$c});
|
3968 |
+
|
3969 |
+
switch (true) {
|
3970 |
+
case $substr_chrs_c_2 == '\b':
|
3971 |
+
$utf8 .= chr(0x08);
|
3972 |
+
++$c;
|
3973 |
+
break;
|
3974 |
+
case $substr_chrs_c_2 == '\t':
|
3975 |
+
$utf8 .= chr(0x09);
|
3976 |
+
++$c;
|
3977 |
+
break;
|
3978 |
+
case $substr_chrs_c_2 == '\n':
|
3979 |
+
$utf8 .= chr(0x0A);
|
3980 |
+
++$c;
|
3981 |
+
break;
|
3982 |
+
case $substr_chrs_c_2 == '\f':
|
3983 |
+
$utf8 .= chr(0x0C);
|
3984 |
+
++$c;
|
3985 |
+
break;
|
3986 |
+
case $substr_chrs_c_2 == '\r':
|
3987 |
+
$utf8 .= chr(0x0D);
|
3988 |
+
++$c;
|
3989 |
+
break;
|
3990 |
+
|
3991 |
+
case $substr_chrs_c_2 == '\\"':
|
3992 |
+
case $substr_chrs_c_2 == '\\\'':
|
3993 |
+
case $substr_chrs_c_2 == '\\\\':
|
3994 |
+
case $substr_chrs_c_2 == '\\/':
|
3995 |
+
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
|
3996 |
+
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
|
3997 |
+
$utf8 .= $chrs{++$c};
|
3998 |
+
}
|
3999 |
+
break;
|
4000 |
+
|
4001 |
+
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
|
4002 |
+
// single, escaped unicode character
|
4003 |
+
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
|
4004 |
+
. chr(hexdec(substr($chrs, ($c + 4), 2)));
|
4005 |
+
$utf8 .= $this->utf162utf8($utf16);
|
4006 |
+
$c += 5;
|
4007 |
+
break;
|
4008 |
+
|
4009 |
+
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
|
4010 |
+
$utf8 .= $chrs{$c};
|
4011 |
+
break;
|
4012 |
+
|
4013 |
+
case ($ord_chrs_c & 0xE0) == 0xC0:
|
4014 |
+
// characters U-00000080 - U-000007FF, mask 1 1 0 X X X X X
|
4015 |
+
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
4016 |
+
$utf8 .= substr($chrs, $c, 2);
|
4017 |
+
++$c;
|
4018 |
+
break;
|
4019 |
+
|
4020 |
+
case ($ord_chrs_c & 0xF0) == 0xE0:
|
4021 |
+
// characters U-00000800 - U-0000FFFF, mask 1 1 1 0 X X X X
|
4022 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
4023 |
+
$utf8 .= substr($chrs, $c, 3);
|
4024 |
+
$c += 2;
|
4025 |
+
break;
|
4026 |
+
|
4027 |
+
case ($ord_chrs_c & 0xF8) == 0xF0:
|
4028 |
+
// characters U-00010000 - U-001FFFFF, mask 1 1 1 1 0 X X X
|
4029 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
4030 |
+
$utf8 .= substr($chrs, $c, 4);
|
4031 |
+
$c += 3;
|
4032 |
+
break;
|
4033 |
+
|
4034 |
+
case ($ord_chrs_c & 0xFC) == 0xF8:
|
4035 |
+
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
4036 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
4037 |
+
$utf8 .= substr($chrs, $c, 5);
|
4038 |
+
$c += 4;
|
4039 |
+
break;
|
4040 |
+
|
4041 |
+
case ($ord_chrs_c & 0xFE) == 0xFC:
|
4042 |
+
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
4043 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
4044 |
+
$utf8 .= substr($chrs, $c, 6);
|
4045 |
+
$c += 5;
|
4046 |
+
break;
|
4047 |
+
|
4048 |
+
}
|
4049 |
+
|
4050 |
+
}
|
4051 |
+
|
4052 |
+
return $utf8;
|
4053 |
+
|
4054 |
+
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
|
4055 |
+
// array, or object notation
|
4056 |
+
|
4057 |
+
if ($str{0} == '[') {
|
4058 |
+
$stk = array(self::SERVICES_JSON_IN_ARR);
|
4059 |
+
$arr = array();
|
4060 |
+
} else {
|
4061 |
+
if ($this->use & self::SERVICES_JSON_LOOSE_TYPE) {
|
4062 |
+
$stk = array(self::SERVICES_JSON_IN_OBJ);
|
4063 |
+
$obj = array();
|
4064 |
+
} else {
|
4065 |
+
$stk = array(self::SERVICES_JSON_IN_OBJ);
|
4066 |
+
$obj = new stdClass();
|
4067 |
+
}
|
4068 |
+
}
|
4069 |
+
|
4070 |
+
array_push($stk, array('what' => self::SERVICES_JSON_SLICE,
|
4071 |
+
'where' => 0,
|
4072 |
+
'delim' => false));
|
4073 |
+
|
4074 |
+
$chrs = substr($str, 1, -1);
|
4075 |
+
$chrs = $this->reduce_string($chrs);
|
4076 |
+
|
4077 |
+
if ($chrs == '') {
|
4078 |
+
if (reset($stk) == self::SERVICES_JSON_IN_ARR) {
|
4079 |
+
return $arr;
|
4080 |
+
|
4081 |
+
} else {
|
4082 |
+
return $obj;
|
4083 |
+
|
4084 |
+
}
|
4085 |
+
}
|
4086 |
+
|
4087 |
+
//print("\nparsing {$chrs}\n");
|
4088 |
+
|
4089 |
+
$strlen_chrs = strlen($chrs);
|
4090 |
+
|
4091 |
+
for ($c = 0; $c <= $strlen_chrs; ++$c) {
|
4092 |
+
|
4093 |
+
$top = end($stk);
|
4094 |
+
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
4095 |
+
|
4096 |
+
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == self::SERVICES_JSON_SLICE))) {
|
4097 |
+
// found a comma that is not inside a string, array, etc.,
|
4098 |
+
// OR we've reached the end of the character list
|
4099 |
+
$slice = substr($chrs, $top['where'], ($c - $top['where']));
|
4100 |
+
array_push($stk, array('what' => self::SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
|
4101 |
+
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
4102 |
+
|
4103 |
+
if (reset($stk) == self::SERVICES_JSON_IN_ARR) {
|
4104 |
+
// we are in an array, so just push an element onto the stack
|
4105 |
+
array_push($arr, $this->decode($slice));
|
4106 |
+
|
4107 |
+
} elseif (reset($stk) == self::SERVICES_JSON_IN_OBJ) {
|
4108 |
+
// we are in an object, so figure
|
4109 |
+
// out the property name and set an
|
4110 |
+
// element in an associative array,
|
4111 |
+
// for now
|
4112 |
+
$parts = array();
|
4113 |
+
|
4114 |
+
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
4115 |
+
// "name":value pair
|
4116 |
+
$key = $this->decode($parts[1]);
|
4117 |
+
$val = $this->decode($parts[2]);
|
4118 |
+
|
4119 |
+
if ($this->use & self::SERVICES_JSON_LOOSE_TYPE) {
|
4120 |
+
$obj[$key] = $val;
|
4121 |
+
} else {
|
4122 |
+
$obj->$key = $val;
|
4123 |
+
}
|
4124 |
+
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
4125 |
+
// name:value pair, where name is unquoted
|
4126 |
+
$key = $parts[1];
|
4127 |
+
$val = $this->decode($parts[2]);
|
4128 |
+
|
4129 |
+
if ($this->use & self::SERVICES_JSON_LOOSE_TYPE) {
|
4130 |
+
$obj[$key] = $val;
|
4131 |
+
} else {
|
4132 |
+
$obj->$key = $val;
|
4133 |
+
}
|
4134 |
+
}
|
4135 |
+
|
4136 |
+
}
|
4137 |
+
|
4138 |
+
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != self::SERVICES_JSON_IN_STR)) {
|
4139 |
+
// found a quote, and we are not inside a string
|
4140 |
+
array_push($stk, array('what' => self::SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
|
4141 |
+
//print("Found start of string at {$c}\n");
|
4142 |
+
|
4143 |
+
} elseif (($chrs{$c} == $top['delim']) &&
|
4144 |
+
($top['what'] == self::SERVICES_JSON_IN_STR) &&
|
4145 |
+
(($chrs{$c - 1} != '\\') ||
|
4146 |
+
($chrs{$c - 1} == '\\' && $chrs{$c - 2} == '\\'))) {
|
4147 |
+
// found a quote, we're in a string, and it's not escaped
|
4148 |
+
array_pop($stk);
|
4149 |
+
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
|
4150 |
+
|
4151 |
+
} elseif (($chrs{$c} == '[') &&
|
4152 |
+
in_array($top['what'], array(self::SERVICES_JSON_SLICE, self::SERVICES_JSON_IN_ARR, self::SERVICES_JSON_IN_OBJ))) {
|
4153 |
+
// found a left-bracket, and we are in an array, object, or slice
|
4154 |
+
array_push($stk, array('what' => self::SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
|
4155 |
+
//print("Found start of array at {$c}\n");
|
4156 |
+
|
4157 |
+
} elseif (($chrs{$c} == ']') && ($top['what'] == self::SERVICES_JSON_IN_ARR)) {
|
4158 |
+
// found a right-bracket, and we're in an array
|
4159 |
+
array_pop($stk);
|
4160 |
+
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
4161 |
+
|
4162 |
+
} elseif (($chrs{$c} == '{') &&
|
4163 |
+
in_array($top['what'], array(self::SERVICES_JSON_SLICE, self::SERVICES_JSON_IN_ARR, self::SERVICES_JSON_IN_OBJ))) {
|
4164 |
+
// found a left-brace, and we are in an array, object, or slice
|
4165 |
+
array_push($stk, array('what' => self::SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
|
4166 |
+
//print("Found start of object at {$c}\n");
|
4167 |
+
|
4168 |
+
} elseif (($chrs{$c} == '}') && ($top['what'] == self::SERVICES_JSON_IN_OBJ)) {
|
4169 |
+
// found a right-brace, and we're in an object
|
4170 |
+
array_pop($stk);
|
4171 |
+
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
4172 |
+
|
4173 |
+
} elseif (($substr_chrs_c_2 == '/*') &&
|
4174 |
+
in_array($top['what'], array(self::SERVICES_JSON_SLICE, self::SERVICES_JSON_IN_ARR, self::SERVICES_JSON_IN_OBJ))) {
|
4175 |
+
// found a comment start, and we are in an array, object, or slice
|
4176 |
+
array_push($stk, array('what' => self::SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
|
4177 |
+
$c++;
|
4178 |
+
//print("Found start of comment at {$c}\n");
|
4179 |
+
|
4180 |
+
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == self::SERVICES_JSON_IN_CMT)) {
|
4181 |
+
// found a comment end, and we're in one now
|
4182 |
+
array_pop($stk);
|
4183 |
+
$c++;
|
4184 |
+
|
4185 |
+
for ($i = $top['where']; $i <= $c; ++$i)
|
4186 |
+
$chrs = substr_replace($chrs, ' ', $i, 1);
|
4187 |
+
|
4188 |
+
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
4189 |
+
|
4190 |
+
}
|
4191 |
+
|
4192 |
+
}
|
4193 |
+
|
4194 |
+
if (reset($stk) == self::SERVICES_JSON_IN_ARR) {
|
4195 |
+
return $arr;
|
4196 |
+
|
4197 |
+
} elseif (reset($stk) == self::SERVICES_JSON_IN_OBJ) {
|
4198 |
+
return $obj;
|
4199 |
+
|
4200 |
+
}
|
4201 |
+
|
4202 |
+
}
|
4203 |
+
}
|
4204 |
+
}
|
4205 |
+
|
4206 |
+
protected function isJsonEncodeEnabled() {
|
4207 |
+
return La_Php::isFunctionEnabled('json_encode');
|
4208 |
+
}
|
4209 |
+
|
4210 |
+
protected function isJsonDecodeEnabled() {
|
4211 |
+
return La_Php::isFunctionEnabled('json_decode');
|
4212 |
+
}
|
4213 |
+
|
4214 |
+
|
4215 |
+
/**
|
4216 |
+
* @todo Ultimately, this should just call PEAR::isError()
|
4217 |
+
*/
|
4218 |
+
function isError($data, $code = null)
|
4219 |
+
{
|
4220 |
+
if (is_object($data) &&
|
4221 |
+
(get_class($data) == 'La_Rpc_Json_Error' || is_subclass_of($data, 'La_Rpc_Json_Error'))) {
|
4222 |
+
return true;
|
4223 |
+
}
|
4224 |
+
return false;
|
4225 |
+
}
|
4226 |
+
}
|
4227 |
+
|
4228 |
+
class La_Rpc_Json_Error {
|
4229 |
+
private $message;
|
4230 |
+
|
4231 |
+
public function __construct($message) {
|
4232 |
+
$this->message = $message;
|
4233 |
+
}
|
4234 |
+
}
|
4235 |
+
|
4236 |
+
|
4237 |
+
} //end La_Rpc_Json
|
4238 |
+
|
4239 |
+
if (!class_exists('La_Rpc_JsonObject', false)) {
|
4240 |
+
class La_Rpc_JsonObject extends La_Object {
|
4241 |
+
|
4242 |
+
public function __construct($object = null) {
|
4243 |
+
if ($object != null) {
|
4244 |
+
$this->initFrom($object);
|
4245 |
+
}
|
4246 |
+
}
|
4247 |
+
|
4248 |
+
public function decode($string) {
|
4249 |
+
if ($string == null || $string == "") {
|
4250 |
+
throw new La_Exception("Invalid format (".get_class($this).")");
|
4251 |
+
}
|
4252 |
+
$string = stripslashes($string);
|
4253 |
+
$json = new La_Rpc_Json();
|
4254 |
+
$object = $json->decode($string);
|
4255 |
+
if (!is_object($object)) {
|
4256 |
+
throw new La_Exception("Invalid format (".get_class($this).")");
|
4257 |
+
}
|
4258 |
+
$this->initFrom($object);
|
4259 |
+
}
|
4260 |
+
|
4261 |
+
private function initFrom($object) {
|
4262 |
+
$object_vars = get_object_vars($object);
|
4263 |
+
foreach ($object_vars as $name => $value) {
|
4264 |
+
if (property_exists($this, $name)) {
|
4265 |
+
$this->$name = $value;
|
4266 |
+
}
|
4267 |
+
}
|
4268 |
+
}
|
4269 |
+
|
4270 |
+
public function encode() {
|
4271 |
+
$json = new La_Rpc_Json();
|
4272 |
+
return $json->encode($this);
|
4273 |
+
}
|
4274 |
+
|
4275 |
+
public function __toString() {
|
4276 |
+
return $this->encode();
|
4277 |
+
}
|
4278 |
+
}
|
4279 |
+
|
4280 |
+
} //end La_Rpc_JsonObject
|
4281 |
+
|
4282 |
+
if (!class_exists('La_Net_Http_Client', false)) {
|
4283 |
+
class La_Net_Http_Client extends La_Net_Http_ClientBase {
|
4284 |
+
|
4285 |
+
protected function isNetworkingEnabled() {
|
4286 |
+
return Gpf::YES;
|
4287 |
+
}
|
4288 |
+
|
4289 |
+
}
|
4290 |
+
|
4291 |
+
} //end La_Net_Http_Client
|
4292 |
+
|
4293 |
+
if (!class_exists('Gpf', false)) {
|
4294 |
+
class Gpf {
|
4295 |
+
const YES = 'Y';
|
4296 |
+
const NO = 'N';
|
4297 |
+
}
|
4298 |
+
}
|
4299 |
+
/*
|
4300 |
+
VERSION
|
4301 |
+
8420bb3c08118181a7f384fda817c252
|
4302 |
+
*/
|
4303 |
+
?>
|
app/code/local/Qualityunit/Liveagent/_Helper/Settings.php
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @copyright Copyright (c) 2007 Quality Unit s.r.o.
|
4 |
+
* @author Juraj Simon
|
5 |
+
* @package WpLiveAgentPlugin
|
6 |
+
* @version 1.0.0
|
7 |
+
*
|
8 |
+
* Licensed under GPL2
|
9 |
+
*/
|
10 |
+
|
11 |
+
class Qualityunit_Liveagent_Helper_Settings {
|
12 |
+
const CACHE_VALIDITY = 600;
|
13 |
+
|
14 |
+
//internal settings
|
15 |
+
const INTERNAL_SETTINGS = 'la-settings_internal-settings';
|
16 |
+
const OWNER_SESSIONID = 'la-settings_owner-sessionid';
|
17 |
+
const OWNER_AUTHTOKEN = 'la-settings_owner-authtoken';
|
18 |
+
const ACCOUNT_STATUS = 'la-settings_accountstatus';
|
19 |
+
const ACCOUNT_NOT_REACHABLE_TIMES = 'la-settings_accountnotreachabletimes';
|
20 |
+
|
21 |
+
|
22 |
+
//general page
|
23 |
+
const GENERAL_SETTINGS_PAGE_NAME = 'la-config-general-page';
|
24 |
+
const SIGNUP_SETTINGS_PAGE_NAME = 'la-config-signup-page';
|
25 |
+
const SIGNUP_WAIT_SETTINGS_PAGE_NAME = 'la-config-signup-wait-page';
|
26 |
+
|
27 |
+
const LA_URL_SETTING_NAME = 'la-url';
|
28 |
+
const LA_OWNER_EMAIL_SETTING_NAME = 'la-owner-email';
|
29 |
+
const LA_USE_API_KEY = 'la-use-api-key';
|
30 |
+
const LA_OWNER_PASSWORD_SETTING_NAME = 'la-owner-password';
|
31 |
+
const GENERAL_SETTINGS_PAGE_STATE_SETTING_NAME = 'general-settings-state';
|
32 |
+
|
33 |
+
//buttons options
|
34 |
+
const BUTTON_CODE = 'la-config-button-code';
|
35 |
+
|
36 |
+
const NO_AUTH_TOKEN = 'no_auth_token';
|
37 |
+
|
38 |
+
const ACCOUNT_STATUS_NOTSET = 'N';
|
39 |
+
const ACCOUNT_STATUS_SET = 'S';
|
40 |
+
|
41 |
+
public function sanitizeUrl($url) {
|
42 |
+
if (stripos($url, 'http://')!==false || stripos($url, 'https://')!==false) {
|
43 |
+
return $url;
|
44 |
+
}
|
45 |
+
return 'http://' . $url;
|
46 |
+
}
|
47 |
+
|
48 |
+
public function getOwnerSessionId() {
|
49 |
+
return $this->getOption(Qualityunit_Liveagent_Helper_Settings::OWNER_SESSIONID);
|
50 |
+
}
|
51 |
+
|
52 |
+
public function getOwnerAuthToken() {
|
53 |
+
$token = $this->getOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN);
|
54 |
+
if ($token == '') {
|
55 |
+
$this->login();
|
56 |
+
$token = $this->getOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN);
|
57 |
+
}
|
58 |
+
return $token;
|
59 |
+
}
|
60 |
+
|
61 |
+
public function login() {
|
62 |
+
$auth = new Qualityunit_Liveagent_Helper_Auth();
|
63 |
+
if ($this->getOption(Qualityunit_Liveagent_Helper_Settings::LA_USE_API_KEY) == 'Y') {
|
64 |
+
//use api and fetch auth token
|
65 |
+
$token = $auth->getauthTokenByApi(null , $this->getOwnerPassword(), $this->getOwnerEmail());
|
66 |
+
$this->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN, $token);
|
67 |
+
return $token;
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
$loginData = $auth->LoginAndGetLoginData();
|
72 |
+
try {
|
73 |
+
$sessionId = $loginData->getValue('session');
|
74 |
+
$this->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_SESSIONID, $sessionId);
|
75 |
+
} catch (La_Data_RecordSetNoRowException $e) {
|
76 |
+
throw new Qualityunit_Liveagent_Exception_ConnectProblem();
|
77 |
+
}
|
78 |
+
try {
|
79 |
+
$token = $loginData->getValue('authtoken');
|
80 |
+
$sessionId = $token;
|
81 |
+
$this->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN, $token);
|
82 |
+
} catch (La_Data_RecordSetNoRowException $e) {
|
83 |
+
// we are communicating with older LA that does not send auth token
|
84 |
+
$this->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN, '');
|
85 |
+
}
|
86 |
+
return $sessionId;
|
87 |
+
}
|
88 |
+
|
89 |
+
public function getLiveAgentUrl() {
|
90 |
+
$url = $this->getOption(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME);
|
91 |
+
if ($url == null) {
|
92 |
+
return $url;
|
93 |
+
}
|
94 |
+
if (strpos($url, 'http://') === false && strpos($url, 'https://') === false) {
|
95 |
+
return 'http://' . $url;
|
96 |
+
}
|
97 |
+
return $url;
|
98 |
+
}
|
99 |
+
|
100 |
+
public function useApiKey() {
|
101 |
+
return $this->getOption(Qualityunit_Liveagent_Helper_Settings::LA_USE_API_KEY) == 'Y';
|
102 |
+
}
|
103 |
+
|
104 |
+
public function getOwnerEmail() {
|
105 |
+
return $this->getOption(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME);
|
106 |
+
}
|
107 |
+
|
108 |
+
public function getOwnerPassword() {
|
109 |
+
return $this->getOption(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME);
|
110 |
+
}
|
111 |
+
|
112 |
+
public function setOption($name, $value) {
|
113 |
+
$setting = Mage::getModel('liveagent/settings')->load($name, 'name');
|
114 |
+
$setting->setValue($value);
|
115 |
+
$setting->setName($name);
|
116 |
+
$setting->save();
|
117 |
+
}
|
118 |
+
|
119 |
+
public function saveDefaultButtonCode() {
|
120 |
+
$this->saveButtonCodeForButtonId('button1');
|
121 |
+
}
|
122 |
+
|
123 |
+
public function saveButtonCodeForButtonId($buttonid) {
|
124 |
+
$url = $this->getLiveAgentUrl();
|
125 |
+
$this->setOption(self::BUTTON_CODE, "
|
126 |
+
<script type=\"text/javascript\">
|
127 |
+
(function(d, src, c) { var t=d.scripts[d.scripts.length - 1],s=d.createElement('script');s.id='la_x2s6df8d';s.async=true;s.src=src;s.onload=s.onreadystatechange=function(){var rs=this.readyState;if(rs&&(rs!='complete')&&(rs!='loaded')){return;}c(this);};t.parentElement.insertBefore(s,t.nextSibling);})(document,
|
128 |
+
'//latrialtst456466.ladesk.com/scripts/track.js',
|
129 |
+
function(e){});
|
130 |
+
</script>
|
131 |
+
");
|
132 |
+
}
|
133 |
+
|
134 |
+
public function getOption($name) {
|
135 |
+
$setting = Mage::getModel('liveagent/settings')->load($name, 'name');
|
136 |
+
return $setting->getData('value');
|
137 |
+
}
|
138 |
+
|
139 |
+
public function getAccountStatus() {
|
140 |
+
return $this->getOption(Qualityunit_Liveagent_Helper_Settings::ACCOUNT_STATUS);
|
141 |
+
}
|
142 |
+
|
143 |
+
public function connectionSettingsAreEmpty() {
|
144 |
+
return $this->getOption(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME) == '' && $this->getOption(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME) == '';
|
145 |
+
}
|
146 |
+
}
|
app/code/local/Qualityunit/Liveagent/_Helper/Signup.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @copyright Copyright (c) 2007 Quality Unit s.r.o.
|
4 |
+
* @author Juraj Simon
|
5 |
+
* @package WpLiveAgentPlugin
|
6 |
+
* @version 1.0.0
|
7 |
+
*
|
8 |
+
* Licensed under GPL2
|
9 |
+
*/
|
10 |
+
|
11 |
+
class Qualityunit_Liveagent_Helper_Signup extends Qualityunit_Liveagent_Helper_Base {
|
12 |
+
|
13 |
+
public function signup($name, $email, $domain, $password, $papVisitorId = '') {
|
14 |
+
$ch = curl_init();
|
15 |
+
$curl_post_data = array(
|
16 |
+
'variation_id' => '3513230f',
|
17 |
+
'customer_email' => $email,
|
18 |
+
'initial_api_key' => $password,
|
19 |
+
'customer_name' => $name,
|
20 |
+
'subdomain' => $domain,
|
21 |
+
'location_id' => 'magento',
|
22 |
+
'apikey' => 'jx5imiBhB6K12zui03YJL0lumHOr7S5T'
|
23 |
+
);
|
24 |
+
curl_setopt($ch,CURLOPT_URL,"https://signup.ladesk.com/api/index.php?handler=accounts&apikey=jx5imiBhB6K12zui03YJL0lumHOr7S5T");
|
25 |
+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
|
26 |
+
curl_setopt($ch, CURLOPT_POST, true);
|
27 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_post_data);
|
28 |
+
$curl_response=curl_exec($ch);
|
29 |
+
if ($curl_response === false) {
|
30 |
+
$info = curl_getinfo($ch);
|
31 |
+
curl_close($ch);
|
32 |
+
throw new Qualityunit_Liveagent_Exception_Base("Error during signup request. Additioanl info:" . var_export($info, true));
|
33 |
+
}
|
34 |
+
$info = curl_getinfo($ch);
|
35 |
+
curl_close($ch);
|
36 |
+
Mage::log('Response info: ' . var_export($info, true));
|
37 |
+
Mage::log('Raw repsonse: ' . $curl_response);
|
38 |
+
$decodedResponse = json_decode($curl_response);
|
39 |
+
if (!isset($decodedResponse->response)) {
|
40 |
+
throw new Qualityunit_Liveagent_Exception_Base("Signup request failed. Please try again...");
|
41 |
+
}
|
42 |
+
if ($info['http_code'] != 200) {
|
43 |
+
throw new Qualityunit_Liveagent_Exception_Base("Signup request failed: " . $decodedResponse->response->errormessage);
|
44 |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Qualityunit_Liveagent_Adminhtml_LiveagentController extends Mage_Adminhtml_Controller_Action {
|
4 |
+
|
5 |
+
const LIVEAGENT_PLUGIN_NAME = 'liveagent';
|
6 |
+
const ACTION_CREATE = 'c';
|
7 |
+
|
8 |
+
/**
|
9 |
+
* @var Qualityunit_Liveagent_Helper_Settings
|
10 |
+
**/
|
11 |
+
private $settings = null;
|
12 |
+
|
13 |
+
private function includePhpApi() {
|
14 |
+
$path = dirname(__FILE__);
|
15 |
+
if (file_exists($path . '/../../Helper/PhpApi.php')) {
|
16 |
+
include_once $path . '/../../Helper/PhpApi.php';
|
17 |
+
return;
|
18 |
+
}
|
19 |
+
include_once ('Qualityunit_Liveagent_Helper_PhpApi.php');
|
20 |
+
}
|
21 |
+
|
22 |
+
protected function _construct() {
|
23 |
+
$this->includePhpApi();
|
24 |
+
Qualityunit_Liveagent_Helper_Data::convertOldButton();
|
25 |
+
parent::_construct();
|
26 |
+
$this->settings = new Qualityunit_Liveagent_Helper_Settings();
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
private function initLayout() {
|
32 |
+
$this->loadLayout()
|
33 |
+
->_setActiveMenu('liveagent/account')
|
34 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Account'), Mage::helper('adminhtml')->__('Settings'));
|
35 |
+
}
|
36 |
+
|
37 |
+
private function doAfterPost($params = array()) {
|
38 |
+
$this->_redirect('*/*', $params);
|
39 |
+
}
|
40 |
+
|
41 |
+
private function doPostAction() {
|
42 |
+
$post = $this->getRequest()->getPost();
|
43 |
+
if (!array_key_exists('action', $post)) {
|
44 |
+
$this->doAfterPost();
|
45 |
+
return;
|
46 |
+
}
|
47 |
+
if ($post['action']=="r") {
|
48 |
+
try {
|
49 |
+
$this->validateSignupMail($post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME]);
|
50 |
+
$this->validateSubdomain($post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME]);
|
51 |
+
$this->registerAccountAction(
|
52 |
+
$post[Qualityunit_Liveagent_Block_Signup::FULL_NAME_FIELD],
|
53 |
+
$post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME],
|
54 |
+
$post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME],
|
55 |
+
md5(rand(90000,99999) . microtime() . rand(90000,99999)),
|
56 |
+
''
|
57 |
+
);
|
58 |
+
} catch (Qualityunit_Liveagent_Exception_SignupFailed $e) {
|
59 |
+
$this->signupFailed($e);
|
60 |
+
return;
|
61 |
+
}
|
62 |
+
$this->doAfterPost();
|
63 |
+
return;
|
64 |
+
}
|
65 |
+
if ($post['action']==Qualityunit_Liveagent_Block_Account::SAVE_ACCOUNT_SETTINGS_ACTION_FLAG) {
|
66 |
+
if (!$this->checkAccountSettings($post)) {
|
67 |
+
$this->doAfterPost($this->getAccountSettingsPost($post));
|
68 |
+
return;
|
69 |
+
}
|
70 |
+
$auth = new Qualityunit_Liveagent_Helper_Auth();
|
71 |
+
try {
|
72 |
+
$auth->ping($post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME]);
|
73 |
+
} catch (Qualityunit_Liveagent_Exception_ConnectProblem $e) {
|
74 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Unable to connect to LiveAgent at') . ' ' . $post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME] . '. ' . $this->getAccountSettingsChangeRevertLink());
|
75 |
+
$this->doAfterPost($this->getAccountSettingsPost($post));
|
76 |
+
return;
|
77 |
+
}
|
78 |
+
if ($this->settings->useApiKey()) {
|
79 |
+
try {
|
80 |
+
$token = $auth->getauthTokenByApi($post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME], $post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME], $post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME]);
|
81 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN, $token);
|
82 |
+
} catch (Qualityunit_Liveagent_Exception_ConnectProblem $e) {
|
83 |
+
Mage::log('Unable to connect to LA: ' . $e->getMessage(), Zend_log::ERR);
|
84 |
+
}
|
85 |
+
if ($token == null) {
|
86 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Unable to login to LiveAgent with given credentails. Please check your url, username and api key.') . ' ' . $this->getAccountSettingsChangeRevertLink());
|
87 |
+
$this->doAfterPost($this->getAccountSettingsPost($post));
|
88 |
+
return;
|
89 |
+
}
|
90 |
+
} else {
|
91 |
+
try {
|
92 |
+
$auth->LoginAndGetLoginData($post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME],
|
93 |
+
$post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME],
|
94 |
+
$post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME]);
|
95 |
+
} catch (Qualityunit_Liveagent_Exception_ConnectProblem $e) {
|
96 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Unable to login to LiveAgent with given credentails. Please check your username and password.') . ' ' . $this->getAccountSettingsChangeRevertLink());
|
97 |
+
$this->doAfterPost($this->getAccountSettingsPost($post));
|
98 |
+
return;
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
$this->saveAccountSettings($post, $token);
|
103 |
+
if (!$this->isSetStatus()) {
|
104 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::ACCOUNT_STATUS, Qualityunit_Liveagent_Helper_Base::ACCOUNT_STATUS_SET);
|
105 |
+
}
|
106 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Account settings were saved successfully'));
|
107 |
+
}
|
108 |
+
if ($post['action']==Qualityunit_Liveagent_Block_Buttoncode::SAVE_BUTTON_CODE_ACTION_FLAG) {
|
109 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::BUTTON_CODE,
|
110 |
+
html_entity_decode($post[Qualityunit_Liveagent_Helper_Settings::BUTTON_CODE]));
|
111 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Button code was saved successfully'));
|
112 |
+
}
|
113 |
+
$this->doAfterPost();
|
114 |
+
}
|
115 |
+
|
116 |
+
private function getAccountSettingsChangeRevertLink() {
|
117 |
+
return '<a href="'.$this->getUrl('*/*').'">' . Mage::helper('adminhtml')->__('Undo this change') . '</a>';
|
118 |
+
}
|
119 |
+
|
120 |
+
private function getAccountSettingsPost($post) {
|
121 |
+
return array(
|
122 |
+
Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME => ' ' . trim(base64_encode($post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME])),
|
123 |
+
Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME => ' ' . trim(base64_encode($post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME])),
|
124 |
+
Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME => ' ' . trim(base64_encode($post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME])),
|
125 |
+
'action' => Qualityunit_Liveagent_Block_Account::CHANGE_ACCOUNT_ACTION_FLAG
|
126 |
+
);
|
127 |
+
}
|
128 |
+
|
129 |
+
private function validateSubdomain($subdomain) {
|
130 |
+
if (0 == preg_match('/^[a-z0-9-]{3,}$/', $subdomain)) {
|
131 |
+
throw new Qualityunit_Liveagent_Exception_SignupFailed(Mage::helper('adminhtml')->__('Please enter valid subdomain name'));
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
private function validateSignupMail($mail) {
|
136 |
+
if (!Zend_Validate::is($mail, 'EmailAddress')) {
|
137 |
+
throw new Qualityunit_Liveagent_Exception_SignupFailed(Mage::helper('adminhtml')->__('Please enter valid email address'));
|
138 |
+
}
|
139 |
+
}
|
140 |
+
|
141 |
+
private function signupFailed($e) {
|
142 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
143 |
+
$this->doAfterPost();
|
144 |
+
}
|
145 |
+
|
146 |
+
public function postAction() {
|
147 |
+
$this->initLayout();
|
148 |
+
try {
|
149 |
+
$this->doPostAction();
|
150 |
+
} catch (Exception $e) {
|
151 |
+
Mage::log($e->getMessage(), Zend_log::ERR);
|
152 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
153 |
+
$this->_redirect('*/*');
|
154 |
+
$this->renderLayout();
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
private function checkAccountSettings($post) {
|
159 |
+
if (trim($post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME]) == null) {
|
160 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Username can not be empty.') . ' ' . $this->getAccountSettingsChangeRevertLink());
|
161 |
+
return false;
|
162 |
+
}
|
163 |
+
if (trim($post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME]) == null) {
|
164 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Password can not be empty.') . ' ' . $this->getAccountSettingsChangeRevertLink());
|
165 |
+
return false;
|
166 |
+
}
|
167 |
+
if (trim($post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME]) == null) {
|
168 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Url can not be empty.') . ' ' . $this->getAccountSettingsChangeRevertLink());
|
169 |
+
return false;
|
170 |
+
}
|
171 |
+
if (strpos($post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME], '@') === false) {
|
172 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Username must be valid email.') . ' ' . $this->getAccountSettingsChangeRevertLink());
|
173 |
+
return false;
|
174 |
+
}
|
175 |
+
return true;
|
176 |
+
}
|
177 |
+
|
178 |
+
private function saveAccountsettings($post, $token = null) {
|
179 |
+
$oldUrl = $this->settings->getOption(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME);
|
180 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME, $post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME]);
|
181 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME, $post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME]);
|
182 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME, $post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME]);
|
183 |
+
if ($this->settings->useApiKey() && $token != '') {
|
184 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN. $token);
|
185 |
+
} else {
|
186 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN, '');
|
187 |
+
}
|
188 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_SESSIONID, '');
|
189 |
+
if ($oldUrl == $post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME]) {
|
190 |
+
return;
|
191 |
+
}
|
192 |
+
if ($this->settings->useApiKey()) {
|
193 |
+
|
194 |
+
} else {
|
195 |
+
$this->settings->saveDefaultButtonCode();
|
196 |
+
}
|
197 |
+
}
|
198 |
+
|
199 |
+
public function indexAction() {
|
200 |
+
$this->initLayout();
|
201 |
+
try {
|
202 |
+
$this->doIndexAction();
|
203 |
+
} catch (Exception $e) {
|
204 |
+
Mage::log($e->getMessage(), Zend_log::ERR);
|
205 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
206 |
+
$this->renderLayout();
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
private function getAccountNotReachableTimes() {
|
211 |
+
$times = $this->settings->getOption(Qualityunit_Liveagent_Helper_Settings::ACCOUNT_NOT_REACHABLE_TIMES);
|
212 |
+
if ($times == '') {
|
213 |
+
return 0;
|
214 |
+
}
|
215 |
+
return $times;
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* @return Qualityunit_Liveagent_Block_Waiting
|
220 |
+
*/
|
221 |
+
private function getWaitingDialog() {
|
222 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::ACCOUNT_NOT_REACHABLE_TIMES, $this->settings->getOption(Qualityunit_Liveagent_Helper_Settings::ACCOUNT_NOT_REACHABLE_TIMES) + 1);
|
223 |
+
return new Qualityunit_Liveagent_Block_Waiting();
|
224 |
+
}
|
225 |
+
|
226 |
+
public function doIndexAction() {
|
227 |
+
if ($this->getRequest()->getParam('action')=="") {
|
228 |
+
if ($this->isNew()) {
|
229 |
+
$block = new Qualityunit_Liveagent_Block_Signup();
|
230 |
+
} else if ($this->isWaiting()) {
|
231 |
+
if ($this->getAccountNotReachableTimes() <= 1) {
|
232 |
+
$block = $this->getWaitingDialog();
|
233 |
+
} else if ($this->getAccountNotReachableTimes() > 1) {
|
234 |
+
if (Qualityunit_Liveagent_Helper_Account::isOnline() || $this->getAccountNotReachableTimes() > 3) {
|
235 |
+
$this->skipWaitAction();
|
236 |
+
$this->renderAccountDialog();
|
237 |
+
$this->renderLayout();
|
238 |
+
return;
|
239 |
+
}
|
240 |
+
$block = $this->getWaitingDialog();
|
241 |
+
}
|
242 |
+
} else {
|
243 |
+
$this->renderAccountDialog();
|
244 |
+
$this->renderLayout();
|
245 |
+
return;
|
246 |
+
}
|
247 |
+
$this->_addContent($this->getLayout()->createBlock($block));
|
248 |
+
$this->renderLayout();
|
249 |
+
return;
|
250 |
+
}
|
251 |
+
if ($this->getRequest()->getParam('action')==Qualityunit_Liveagent_Block_Account::CANCEL_ACCOUNT_ACTION_FLAG) {
|
252 |
+
$this->resetAccountAction();
|
253 |
+
$block = new Qualityunit_Liveagent_Block_Signup();
|
254 |
+
}
|
255 |
+
if ($this->getRequest()->getParam('action') == Qualityunit_Liveagent_Block_Account::CHANGE_ACCOUNT_ACTION_FLAG) {
|
256 |
+
$block = new Qualityunit_Liveagent_Block_Account();
|
257 |
+
}
|
258 |
+
if ($this->getRequest()->getParam('action')=="s") {
|
259 |
+
$this->skipWaitAction();
|
260 |
+
$this->renderAccountDialog();
|
261 |
+
$this->renderLayout();
|
262 |
+
return;
|
263 |
+
}
|
264 |
+
$this->_addContent($this->getLayout()->createBlock($block));
|
265 |
+
$this->renderLayout();
|
266 |
+
}
|
267 |
+
|
268 |
+
private function checkButtonCodeIsEmpty() {
|
269 |
+
if ($this->settings->getOption(Qualityunit_Liveagent_Helper_Settings::BUTTON_CODE) == null) {
|
270 |
+
Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('adminhtml')->__('The chat button is currently disabled.'));
|
271 |
+
}
|
272 |
+
}
|
273 |
+
|
274 |
+
private function renderAccountDialog() {
|
275 |
+
if ($this->isSetStatus() && Qualityunit_Liveagent_Helper_Account::isOnline()) {
|
276 |
+
$this->checkButtonCodeIsEmpty();
|
277 |
+
$block = new Qualityunit_Liveagent_Block_Buttoncode();
|
278 |
+
}
|
279 |
+
if ($this->isSetStatus() && !Qualityunit_Liveagent_Helper_Account::isOnline()) {
|
280 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Unable to connect LiveAgent at') . ' ' . $this->settings->getLiveAgentUrl());
|
281 |
+
$block = new Qualityunit_Liveagent_Block_Account();
|
282 |
+
}
|
283 |
+
if (!$this->isSetStatus()) {
|
284 |
+
$block = new Qualityunit_Liveagent_Block_Account();
|
285 |
+
}
|
286 |
+
$this->_addContent($this->getLayout()->createBlock($block));
|
287 |
+
}
|
288 |
+
|
289 |
+
private function isNew() {
|
290 |
+
return $this->settings->getAccountStatus() == Qualityunit_Liveagent_Helper_Base::ACCOUNT_STATUS_NOTSET;
|
291 |
+
}
|
292 |
+
|
293 |
+
private function isSetStatus() {
|
294 |
+
return $this->settings->getAccountStatus() == Qualityunit_Liveagent_Helper_Base::ACCOUNT_STATUS_SET;
|
295 |
+
}
|
296 |
+
|
297 |
+
private function isWaiting() {
|
298 |
+
return $this->settings->getAccountStatus() == Qualityunit_Liveagent_Helper_Base::ACCOUNT_STATUS_WAIT;
|
299 |
+
}
|
300 |
+
|
301 |
+
private function resetAccountAction() {
|
302 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::LA_USE_API_KEY, 'Y');
|
303 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::ACCOUNT_STATUS, Qualityunit_Liveagent_Helper_Base::ACCOUNT_STATUS_NOTSET);
|
304 |
+
}
|
305 |
+
|
306 |
+
private function sendSignupRequest($name, $email, $domain, $password, $papvisitorId) {
|
307 |
+
$signupHelper = new Qualityunit_Liveagent_Helper_Signup();
|
308 |
+
try {
|
309 |
+
$response = $signupHelper->signup($name, $email, $domain, $password, $papvisitorId);
|
310 |
+
} catch (Qualityunit_Liveagent_Exception_Base $e) {
|
311 |
+
throw new Qualityunit_Liveagent_Exception_SignupFailed($e->getMessage());
|
312 |
+
}
|
313 |
+
Mage::log("Signup response recieved: " . print_r($response, true), Zend_log::DEBUG);
|
314 |
+
Mage::log("Response OK", Zend_log::DEBUG);
|
315 |
+
}
|
316 |
+
|
317 |
+
private function registerAccountAction($name, $email, $domain, $password, $papvisitorId) {
|
318 |
+
$this->sendSignupRequest($name, $email, $domain, $password, $papvisitorId);
|
319 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME, 'http://' . $domain . '.ladesk.com');
|
320 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME, $email);
|
321 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME, $password);
|
322 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::LA_USE_API_KEY, 'Y');
|
323 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN, '');
|
324 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_SESSIONID, '');
|
325 |
+
$this->settings->saveDefaultButtonCode();
|
326 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::ACCOUNT_STATUS, Qualityunit_Liveagent_Helper_Base::ACCOUNT_STATUS_WAIT);
|
327 |
+
}
|
328 |
+
|
329 |
+
private function skipWaitAction() {
|
330 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::LA_USE_API_KEY, 'Y');
|
331 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::ACCOUNT_STATUS, Qualityunit_Liveagent_Helper_Base::ACCOUNT_STATUS_SET);
|
332 |
+
$this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::ACCOUNT_NOT_REACHABLE_TIMES, 0);
|
333 |
+
}
|
334 |
+
}
|
app/code/local/Qualityunit/Liveagent/_controllers/IndexController.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Qualityunit_Liveagent_IndexController extends Mage_Core_Controller_Front_Action {
|
3 |
+
public function indexAction() {
|
4 |
+
Qualityunit_Liveagent_Helper_Data::convertOldButton();
|
5 |
+
$this->loadLayout();
|
6 |
+
$this->renderLayout();
|
7 |
+
}
|
8 |
+
}
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Liveagent</name>
|
4 |
-
<version>2.5.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.gnu.org/licenses/gpl-3.0.txt">GPLv3</license>
|
7 |
<channel>community</channel>
|
@@ -10,11 +10,11 @@
|
|
10 |
<description>Magento-LiveAgent plugin integrates full featured help desk and live chat software Live Agent into any Magento installation.
|
11 |
Simply add "start chat" button by few simple clicks and be live within 5 minutes.</description>
|
12 |
<notes>changes:
|
13 |
-
- connection
|
14 |
<authors><author><name>Juraj Simon</name><user>jurajsim</user><email>jsimon@qualityunit.com</email></author></authors>
|
15 |
<date>2015-07-20</date>
|
16 |
-
<time>
|
17 |
-
<contents><target name="magelocal"><dir name="Qualityunit"><dir name="Liveagent"><dir name="Block"><file name="Account.php" hash="0a8f24293b3fb9c11dfdb1fa84924389"/><file name="Base.php" hash="5f7aa2fee0855449b968df556f6ade12"/><file name="Buttoncode.php" hash="e99d54a5fb6073ffbc75286254a371d8"/><file name="Signup.php" hash="05d9c1abd21727b13a3120b0c9fdbc62"/><file name="Waiting.php" hash="f77602ac728f2b8b2eab9a4c4c864d9d"/></dir><dir name="Exception"><file name="Base.php" hash="6efd9dcda657c33bc9cfe6709300b883"/><file name="ConnectProblem.php" hash="f2c9840d533e6389ba84989337de32c9"/><file name="SignupFailed.php" hash="e370773d3b306bb8c24e5263d1491860"/></dir><dir name="Helper"><file name="Account.php" hash="8ca177266bd600874cac584a55a5c694"/><file name="Auth.php" hash="c02f7300b35b77e6a30ada49ea6ccefd"/><file name="Base.php" hash="5d7b663453478d14458103a694ab9137"/><file name="Data.php" hash="40b54155794999d0085be4f05889954f"/><file name="PhpApi.php" hash="adb77eb5ef4cc7a2d5b2adc076a3ee81"/><file name="Settings.php" hash="b78e5f9a6c6c98ae2425e1a3be2fc7c8"/><file name="Signup.php" hash="6ed0f547cc736d70cf63d4408eedfd0c"
|
18 |
<compatible/>
|
19 |
<dependencies><required><php><min>5.2.0</min><max>5.6.0</max></php><extension><name>curl</name><min/><max/></extension></required></dependencies>
|
20 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Liveagent</name>
|
4 |
+
<version>2.5.10</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.gnu.org/licenses/gpl-3.0.txt">GPLv3</license>
|
7 |
<channel>community</channel>
|
10 |
<description>Magento-LiveAgent plugin integrates full featured help desk and live chat software Live Agent into any Magento installation.
|
11 |
Simply add "start chat" button by few simple clicks and be live within 5 minutes.</description>
|
12 |
<notes>changes:
|
13 |
+
- fixed some connection issues</notes>
|
14 |
<authors><author><name>Juraj Simon</name><user>jurajsim</user><email>jsimon@qualityunit.com</email></author></authors>
|
15 |
<date>2015-07-20</date>
|
16 |
+
<time>14:56:05</time>
|
17 |
+
<contents><target name="magelocal"><dir name="Qualityunit"><dir name="Liveagent"><dir name="Block"><file name="Account.php" hash="0a8f24293b3fb9c11dfdb1fa84924389"/><file name="Base.php" hash="5f7aa2fee0855449b968df556f6ade12"/><file name="Buttoncode.php" hash="e99d54a5fb6073ffbc75286254a371d8"/><file name="Signup.php" hash="05d9c1abd21727b13a3120b0c9fdbc62"/><file name="Waiting.php" hash="f77602ac728f2b8b2eab9a4c4c864d9d"/></dir><dir name="Exception"><file name="Base.php" hash="6efd9dcda657c33bc9cfe6709300b883"/><file name="ConnectProblem.php" hash="f2c9840d533e6389ba84989337de32c9"/><file name="SignupFailed.php" hash="e370773d3b306bb8c24e5263d1491860"/></dir><dir name="Helper"><file name="Account.php" hash="8ca177266bd600874cac584a55a5c694"/><file name="Auth.php" hash="c02f7300b35b77e6a30ada49ea6ccefd"/><file name="Base.php" hash="5d7b663453478d14458103a694ab9137"/><file name="Data.php" hash="40b54155794999d0085be4f05889954f"/><file name="PhpApi.php" hash="adb77eb5ef4cc7a2d5b2adc076a3ee81"/><file name="Settings.php" hash="b78e5f9a6c6c98ae2425e1a3be2fc7c8"/><file name="Signup.php" hash="6ed0f547cc736d70cf63d4408eedfd0c"/></dir><dir name="Model"><file name="Buttons.php" hash="30907d56865e8e8d182cc6e8d1e7de14"/><file name="Liveagent.php" hash="3288b2194ace43971bb07f9ee05e25f0"/><dir name="Mysql4"><dir name="Buttons"><file name="Collection.php" hash="64edb5ecfc9b1511ae155f347e9a0e6b"/></dir><file name="Buttons.php" hash="5c2fd7184c1bb88b381ef8440bfe1e4f"/><dir name="Liveagent"><file name="Collection.php" hash="29675fde5a317fdf980a549f40502b8e"/></dir><file name="Liveagent.php" hash="559e305b52289e79f9038aea53a85a48"/><dir name="Settings"><file name="Collection.php" hash="d9dfc6b2abadf95ad6dbdee9f52f9c28"/></dir><file name="Settings.php" hash="cdded3171b84b02ed4ad360dd3cb7b71"/></dir><file name="Settings.php" hash="96e3fb575bfbee4181a9e70065cc42dc"/><file name="Status.php" hash="c743fdabadd7527820e7b8ede6937f38"/></dir><dir name="_Block"><file name="Account.php" hash="0a8f24293b3fb9c11dfdb1fa84924389"/><file name="Base.php" hash="5f7aa2fee0855449b968df556f6ade12"/><file name="Buttoncode.php" hash="e99d54a5fb6073ffbc75286254a371d8"/><file name="Signup.php" hash="05d9c1abd21727b13a3120b0c9fdbc62"/><file name="Waiting.php" hash="f77602ac728f2b8b2eab9a4c4c864d9d"/></dir><dir name="_Helper"><file name="Account.php" hash="8ca177266bd600874cac584a55a5c694"/><file name="Auth.php" hash="c02f7300b35b77e6a30ada49ea6ccefd"/><file name="Base.php" hash="5d7b663453478d14458103a694ab9137"/><file name="Data.php" hash="40b54155794999d0085be4f05889954f"/><file name="PhpApi.php" hash="adb77eb5ef4cc7a2d5b2adc076a3ee81"/><file name="Settings.php" hash="b78e5f9a6c6c98ae2425e1a3be2fc7c8"/><file name="Signup.php" hash="6ed0f547cc736d70cf63d4408eedfd0c"/><file name=".Auth.php.swp" hash="f261f67ddcfc50fd832c42495a9fc53a"/></dir><dir name="_controllers"><dir name="Adminhtml"><file name="LiveagentController.php" hash="dcedbdb68831ff96de2f92c5b6aa099c"/></dir><file name="IndexController.php" hash="2af5a61bf7319c38c97a48e0f3723598"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="LiveagentController.php" hash="dcedbdb68831ff96de2f92c5b6aa099c"/></dir><file name="IndexController.php" hash="2af5a61bf7319c38c97a48e0f3723598"/></dir><dir name="etc"><file name="config.xml" hash="c4c252b355417d64689df9acbada7f7b"/></dir><dir name="sql"><dir name="liveagent_setup"><file name="mysql4-install-0.1.0.php" hash="68891e5aca423bbb7226975413cd82b8"/><file name="mysql4-install-2.5.4.php" hash="2bd7ec4b4c8a366bed9f3afc264ae897"/></dir></dir></dir><file name=".buildpath" hash="0d2475e3be03419439e2a22ebc4e0813"/><file name=".project" hash="41fa1353a5ab19352d5636d52e17351d"/><dir name=".settings"><file name="org.eclipse.php.core.prefs" hash="abf8f34f8087365ab830524698638d7c"/><file name="org.eclipse.wst.jsdt.ui.superType.container" hash="b27d1cf62dde4473bab7c433317bb0ce"/><file name="org.eclipse.wst.jsdt.ui.superType.name" hash="c89686a387d2b12b3c729ce35a0bcb5b"/><file name=".jsdtscope" hash="d098ed1fa924b2d9d9cb377fb391d758"/></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="liveagent.xml" hash="e07cbd75c0faa7d86c9c0a8a2ff53df1"/></dir><dir name="template"><dir name="liveagent"><file name="button.phtml" hash="3cef6df19c905140c8c8ce01520f0ebd"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Qualityunit_Liveagent.xml" hash="db13786c45588e15d5a390201a1709e4"/></dir></target><target name="magelocale"><dir name="en_US"><file name="qualityunit_liveagent.csv" hash="234db3c1cdc05df98928ae633500bc04"/></dir></target></contents>
|
18 |
<compatible/>
|
19 |
<dependencies><required><php><min>5.2.0</min><max>5.6.0</max></php><extension><name>curl</name><min/><max/></extension></required></dependencies>
|
20 |
</package>
|