-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreCondition.php
69 lines (63 loc) · 2.67 KB
/
PreCondition.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
class PreCondition
{
private function file_get_contents_curl($url) {
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
return $query;
}
private function GetFileUrlFromPortfolio($PortfolioURL){
$page = $this->file_get_contents_curl($PortfolioURL);
preg_match_all('/href="\/pic.*/', $page, $file);
$file = preg_replace(array('/href="/', '/html.*/'), "", $file[0][0])."html";
return "http://www.shutterstock.com".$file;
}
private function GetPortfolioUrlFromFilePage($filePage){
$page = $this->file_get_contents_curl($filePage);
preg_match_all('/id="portfolio_link.*/', $page, $file);
$PortfolioURL = preg_replace(array('/.*href="/','/">/'), "", $file[0][0]);
return "http://www.shutterstock.com".$PortfolioURL;
}
private function GetNormalURL($PortfolioURL){
$filePage = $this->GetFileUrlFromPortfolio($PortfolioURL);
$PortfolioURL = $this->GetPortfolioUrlFromFilePage($filePage);
return $PortfolioURL;
}
private function NormalizationItemsArray($ItemsArray){
$newItems = array();
foreach ($ItemsArray as $item) {
$handle = curl_init($item['thumb']);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($handle);
/* Check for 404 (file not found). */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($httpCode != 404) {
$newItems[$item['item_id']] = $item['thumb'];
}
curl_close($handle);
}
return $newItems;
}
/*
$file - name of file
*/
public function PreConditions($file){
$file = json_decode(file_get_contents($file),true);
$file['shutterstock_profile_url'] = $this->GetNormalURL($file['shutterstock_profile_url']);
$file['items'] = $this->NormalizationItemsArray($file['items']);
exec("mkdir ".$file['user_id']);
exec("mkdir ".$file['user_id']."/ShutterFiles");
exec("mkdir ".$file['user_id']."/Results");
exec("mkdir ".$file['user_id']."/DepositFiles");
exec("mkdir ".$file['user_id']."/Data");
return $file;
}
}
// $norm = new NormalizationPortfolioURL();
// $norm->PreConditions("http://www.shutterstock.com/cat.mhtml?gallery_id=844213");