-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedinURLValidator.php
More file actions
executable file
·125 lines (82 loc) · 2.33 KB
/
linkedinURLValidator.php
File metadata and controls
executable file
·125 lines (82 loc) · 2.33 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
<?php
/*
* linkedinURLValidator class is used to validate the linkedin public url.
*
* @package: linkedinURLValidator
* @author: Gowri sankar <gchokeen@gmail.com>
* @link: http://www.code-cocktail.in
*/
class linkedinURLValidator{
private $url;
private $pattern;
private $result;
public function __construct($url){
$this->url = $url;
$this->pattern = '';
$this->result = '';
}
public function validate(){
if($this->is_url($this->url)){
$companycheck = $this->is_company();
$personcheck = $this->is_person();
if(count($personcheck) != 0){
$is_customized = $this->is_customized();
return array('valid'=>1,'type'=>'person','customized'=>$is_customized);
}
else if(count($companycheck) != 0){
return array('valid'=>1,'type'=>'company');
}
else{
return array('valid'=>0);
}
}
else{
return array('valid'=>0,'error'=>'This is not a valid url');
}
}
public function is_person(){
$this->pattern = '/((http?|https)\:\/\/)?([a-zA-Z]+)\.linkedin.com\/[a-z]{2}\/[a-zA-Z0-9]{5,30}/i';
preg_match($this->pattern, $this->url, $this->result);
return $this->result;
}
public function is_company(){
$this->pattern = '/((http?|https)\:\/\/)?([a-zA-Z]+)\.linkedin.com\/company\/[a-zA-Z0-9]{5,30}/i';
preg_match($this->pattern, $this->url, $this->result);
return $this->result;
}
public function get_company_id(){
if($result=$this->is_company()){
return $lastSegment = basename(parse_url($result[0], PHP_URL_PATH));
}
else{
return false;
}
}
/*
* @return: 0-not customized, 1 - customized
*/
public function is_customized(){
$this->pattern = '/((http?|https)\:\/\/)?([a-zA-Z]+)\.linkedin.com\/pub\//i';
preg_match($this->pattern, $this->url, $this->result);
return (count($this->result)==0?1:0);
}
private function is_url($url){
if(filter_var($url, FILTER_VALIDATE_URL) === FALSE)
{
return false;
}else{
return true;
}
}
/*
*convert_global_url method will convert the linkedin public url with www
*@method : convert_global_url
*
*/
public function convert_global_url(){
$this->pattern = '#(https?://)?\w+\.linkedin.com(?=[/\s]|$)#i';
$this->result = preg_replace($this->pattern,'http://www.linkedin.com', $this->url);
return $this->result;
}
}
?>