forked from kaltura/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KAsyncNotifierParamsUtils.class.php
129 lines (113 loc) · 2.72 KB
/
KAsyncNotifierParamsUtils.class.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
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
<?php
/**
*
*
* @package Scheduler
* @subpackage Notifier
*
*/
class KAsyncNotifierParamsUtils
{
public static function prepareNotificationData($url, $signature_key, KalturaBatchJob $job, KalturaNotificationJobData $data, $prefix = null)
{
$params = array("notification_id" => $job->id, "notification_type" => $data->typeAsString, "puser_id" => $data->userId, "partner_id" => $job->partnerId);
switch($data->objType)
{
case KalturaNotificationObjectType::USER:
$params["user_id"] = $data->objectId;
break;
case KalturaNotificationObjectType::ENTRY:
$params["entry_id"] = $data->objectId;
break;
case KalturaNotificationObjectType::KSHOW:
$params["kshow_id"] = $data->objectId;
break;
case KalturaNotificationObjectType::BATCH_JOB:
$params["job_id"] = $data->objectId;
break;
default:
// VERY STARANGE - either objType not set properly or some error !
}
$object_data_params = self::getDataAsArray($data->data);
if($object_data_params)
{
$params = array_merge($params, $object_data_params);
}
$params = self::fixParams($params, $prefix);
$params['signed_fields'] = '';
foreach($params as $key => $value)
{
$params['signed_fields'] .= $key . ',';
}
return self::signParams($signature_key, $params);
}
/**
* @param unknown_type $serialized_data
* @return unknown|mixed|multitype:unknown |NULL
*/
public static function getDataAsArray($serialized_data)
{
if (empty($serialized_data))
return null;
if(is_array($serialized_data))
return $serialized_data;
if(is_string($serialized_data))
{
try{
$tmp = unserialize($serialized_data);
if(is_array($tmp))
return $tmp;
}
catch(Exception $e){
}
return array($serialized_data);
}
return null;
}
/**
* @param string $signature_key
* @param array $params
* @return array
*/
public static function signParams($signature_key, &$params)
{
list($sig, $raw_str) = self::signature($signature_key, $params);
$params["sig"] = $sig;
return array($params, $raw_str);
}
/**
* @param string $signature_key
* @param array $params
* @return string
*/
private static function signature($signature_key, $params)
{
ksort($params);
$str = "";
foreach($params as $k => $v)
{
if($k == "sig")
continue;
$str .= $k . $v;
}
return array(md5($signature_key . $str), $str);
}
/**
* @param array $params
* @param string $prefix
* @return array
*/
private static function fixParams(&$params, $prefix = null)
{
$new_params = array();
foreach($params as $k => $v)
{
if($prefix)
$new_params[$prefix . trim($k)] = trim($v);
else
$new_params[trim($k)] = trim($v);
}
return $new_params;
}
}
?>