forked from straup/php-lib-enplacify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_enplacify.php
101 lines (69 loc) · 2.05 KB
/
lib_enplacify.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
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
<?php
#
# $Id$
#
######################################################
function enplacify_uri($uri){
foreach ($GLOBALS['cfg']['enplacify'] as $service => $data){
foreach ($data['uris'] as $pattern){
if (! preg_match($pattern, $uri)){
continue;
}
$service_lib = "enplacify_{$service}";
$service_func = "enplacify_{$service}_uri";
loadlib($service_lib);
$rsp = call_user_func_array($service_func, array($uri));
return $rsp;
}
}
return array(
'ok' => 0,
'error' => 'failed to locate any valid services for URL',
);
}
######################################################
function enplacify_machinetags(&$tags, &$valid_machinetags){
# return array( 'ok' => 0, 'error' => 'this does not work yet...' );
# TODO: do machinetag vs. plaintag filtering outside
# this function (20101211/straup)
foreach ($tags as $tag){
if (! $tag['machine_tag']){
continue;
}
list($nspred, $value) = explode("=", $tag['raw'], 2);
list($ns, $pred) = explode(":", $nspred, 2);
if (! isset($valid_machinetags[$ns])){
continue;
}
if (! in_array($pred, $valid_machinetags[$ns])){
continue;
}
$rsp = enplacify_uri($tag['raw']);
if ($rsp['ok']){
return $rsp;
}
}
return array( 'ok' => 0, 'error' => 'unable to enplacify machine tags' );
}
######################################################
# This is just a generic wrapper because most services only
# only need to have a single identifier teased out of a given
# URI. It's meant to be called *inside* of a service specific
# function. Or not. See also: enplacify_dopplr_uri_to_id()
# (20101211/straup)
function enplacify_service_uri_to_id($service, $uri){
if (! isset($GLOBALS['cfg']['enplacify'][ $service ])){
return null;
}
$service_id = null;
$uris = $GLOBALS['cfg']['enplacify'][ $service ]['uris'];
foreach ($uris as $pattern){
if (preg_match($pattern, $uri, $m)){
$service_id = $m[1];
break;
}
}
return $service_id;
}
######################################################
?>