TrashController.php
8.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
namespace controllers;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class TrashController extends \Phalcon\Mvc\Controller
{
function indexAction()
{
$page = '';
$items = array();
$final_list = array();
$result = array();
$item_reg = '/class="tabletitle"/';
$link_reg = '/<td><a href="([^t]*)">Поиск<\/a><\/td>/';
$items_reg = '/<td class="tabletitle" colspan="12">(.*?)<\/td><\/tr><tr>(.*?)<\/tr>/';
$item_name = '/<a .*>(.*)<\/a>/';
$item_desc = '/<div class="descblock">(.*)<\/div>/';
$item_price = '/<td class="price" align="right">(.*)<\/td>/';
if ($this->request->hasFiles() == true) {
//Print the real file names and their sizes
foreach ($this->request->getUploadedFiles() as $file) {
//Move the file into the application
$route = STORAGE_PATH . 'temp/' . $file->getName();
$file->moveTo($route);
}
$this->exelphp->addFile($route);
$result = $this->exelphp->getRows();
}
foreach($result as $row){
$proxy = \proxy::getInstance();
$page = $this->parseExistLink('price.aspx?sr=-4&pcode='.$row[1],$proxy->getProxy());
$check_items = preg_match($item_reg, $page, $check);
if($check_items){
preg_match_all($items_reg, $page, $one_item);
$items[] = $one_item;
} else {
preg_match_all($link_reg, $page, $links);
$items = array();
foreach($links[1] as $link){
$page = $this->parseExistLink($link,$proxy->getProxy());
preg_match_all($items_reg, $page, $one_item);
$items[] = $one_item;
}
}
die(print_r($items));
if(!empty($items)){
$num = count($items);
for($i=0; $i<$num; $i++){
/*$sub_num = count($items[$i][1]);
for($x=0; $x<$sub_num; $x++){
$final_list[$i][$x] = preg_split('/\|+/', preg_replace('/<(.*?)>/', '|', $items[$i][0][$x]));
}*/
preg_match_all( $item_name, $items[$i][0][0], $name);
//$final_list[] = $name;
}
} else {
die('по запросу ничего не найдено');
}
// Array
// (
// [0] => Array
// (
// [0] => Array
// (
// [0] => <td class="tabletitle" colspan="12">• Запрошенный артикул</td></tr><tr id="_0_" attr="firm_1260" bl="-10"><td><div class="artblock"><div class="firmname"><a href="/hint/?s=a00006dd-4ec8-4000-bce3-d00000c00000" onclick='javascript:ShowTipLayer(this,event,this.href, 30,130); return false;'>Bearmach</a></div><div class="art">CA......CL</div></div><div class="descblock">Брызговики передние</div></td><td class="informicon" align="center"></td><td align="center"></td><td class="statis mobile_h">---</td><td class="price" align="right">---</td><td></td></tr>
// [1] => <td class="tabletitle" colspan="12">• Предложения по оригинальным производителям</td></tr><tr id="_1_" attr="firm_59" bl="-1"><td><div class="artblock"><div class="firmname"><a href="/hint/?s=78411e5b-0037-403b-bae3-0426e0004dc5" onclick='javascript:ShowTipLayer(this,event,this.href, 30,130); return false;'>Land Rover</a></div><div class="art">CA......CL</div></div><div class="descblock">Брызговики передние RR Sport</div></td><td class="informicon" align="center"><a target='_blank' rel='popup_window_51eefed0-2178-4e7b-b388-1d8f90300058' href='/Parts.axd?pid=20504A03&flag=419449380'><span class="img"></span><span class="appl"></span></a></td><td align="center">1</td><td class="statis mobile_h">3 дн.<span class="none" title="Нет данных"></span></td><td class="price" align="right">2 262,00грн.</td><td class="basket"><a title="В вашей корзине: 0 шт." onclick="wait(this);" href="/profile/orders/basket.aspx?pid=BE109952_010000004d005b57018a6e1e000042bb&sr=-4"></a></td></tr>
// )
//
// [1] => Array
// (
// [0] => • Запрошенный артикул
// [1] => • Предложения по оригинальным производителям
// )
//
// [2] => Array
// (
// [0] => id="_0_" attr="firm_1260" bl="-10"><td><div class="artblock"><div class="firmname"><a href="/hint/?s=a00006dd-4ec8-4000-bce3-d00000c00000" onclick='javascript:ShowTipLayer(this,event,this.href, 30,130); return false;'>Bearmach</a></div><div class="art">CA......CL</div></div><div class="descblock">Брызговики передние</div></td><td class="informicon" align="center"></td><td align="center"></td><td class="statis mobile_h">---</td><td class="price" align="right">---</td><td></td>
// [1] => id="_1_" attr="firm_59" bl="-1"><td><div class="artblock"><div class="firmname"><a href="/hint/?s=78411e5b-0037-403b-bae3-0426e0004dc5" onclick='javascript:ShowTipLayer(this,event,this.href, 30,130); return false;'>Land Rover</a></div><div class="art">CA......CL</div></div><div class="descblock">Брызговики передние RR Sport</div></td><td class="informicon" align="center"><a target='_blank' rel='popup_window_51eefed0-2178-4e7b-b388-1d8f90300058' href='/Parts.axd?pid=20504A03&flag=419449380'><span class="img"></span><span class="appl"></span></a></td><td align="center">1</td><td class="statis mobile_h">3 дн.<span class="none" title="Нет данных"></span></td><td class="price" align="right">2 262,00грн.</td><td class="basket"><a title="В вашей корзине: 0 шт." onclick="wait(this);" href="/profile/orders/basket.aspx?pid=BE109952_010000004d005b57018a6e1e000042bb&sr=-4"></a></td>
// )
//
// )
//
//
// )
}
/* if((isset($price) && !empty($price)) && (isset($h1) && !empty($h1))) {
$price = preg_replace("/[^0-9]/", '', $price[1]);
}*/
$this->view->setVars([
'data' =>$final_list
]);
}
public function parseExistLink($url,$proxy){
$url = 'http://www.exist.ua/'.$url;
$proxy = explode(':', $proxy);
//$proxyauth = 'RUS143854:Z8lhjhYPUP';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
//curl_setopt($ch, CURLOPT_PROXYTYPE, 7);
curl_setopt($ch, CURLOPT_PROXY, $proxy[0]);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy[1]);
// curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");
$headers = array
(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8',
'Accept-Language: ru,en-us;q=0.7,en;q=0.3',
'Accept-Encoding: deflate',
'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7'
);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
sleep(5);
$exec = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return preg_replace('/>\s*</', '><', $exec);
}
function addAction()
{
$model = new \rdsServices;
$model->save();
$model = \rdsServices::find(array("order" => 'id'));
$model = $model->getLast();
$this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT);
$this->view->setVars([
'item' => $model,
]);
}
function deleteAction()
{
$id = $this->request->get('id');
$model = \rdsServices::findFirst("id = '$id'");
if($model instanceof \rdsServices) {
$model->delete();
}
}
function updateAction()
{
$data = $this->request->getPost('data');
$id = $this->request->getPost('id');
$data = json_decode($data);
$model = \rdsServices::findFirst(array("id = '$id'"));
foreach(get_object_vars($data) as $key=>$value) {
$array[$key] = $value;
}
$model->save($array);
die();
}
}