forked from kaltura/KalturaAPISampleListEntries
/
getlist.php
170 lines (154 loc) · 8.44 KB
/
getlist.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
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
<?php
function truncateWords($input, $numwords, $padding="...")
{
$output = strtok($input, " \n");
while(--$numwords > 0) $output .= " " . strtok(" \n");
if($output != $input) $output .= $padding;
$output = trim($output);
if ($output == $padding) $output = '';
return $output;
}
function prepareDescription ($desc) {
$truncated = truncateWords($desc, 10);
$output = ($truncated == '') ? '' : '<span title="'.$desc.'">'.$truncated.'</span>';
return $output;
}
function tep_rewrite_email($content) {
$email_patt = '([A-Za-z0-9._%-]+)\@([A-Za-z0-9._%-]+)\.([A-Za-z0-9._%-]+)';
$mailto_pattern = '#\<a[^>]*?href=\"mailto:\s?' . $email_patt . '[^>]*?\>[^>]*?<\/a\>#';
$rewrite_result = '<span title="\\1@\\2.\\3">\\1...</span>';
$content = preg_replace($mailto_pattern, $rewrite_result, $content);
$content = preg_replace('#' . $email_patt . '#', $rewrite_result, $content);
return $content;
}
require_once('php5/KalturaClient.php');
require_once('kalturaconf.php');
$config = new KalturaConfiguration($partnerId);
$config->serviceUrl = 'https://www.kaltura.com';
$client = new KalturaClient($config);
$ks = $client->generateSession($adminSecret, $userId, KalturaSessionType::ADMIN, $partnerId);
$client->setKs($ks);
$filter = new KalturaMediaEntryFilter();
$pager = new KalturaFilterPager();
$codesample = 'require_once(\'php5/KalturaClient.php\');' . PHP_EOL .
'$adminSecret = \'your-api-admin-secret\';' . PHP_EOL .
'$partnerId = 000; //your partner id' . PHP_EOL .
'$userId = \'listentriestool\'; //this can be the logged-in admin user for tracking/auditing purposes' . PHP_EOL .
'$config = new KalturaConfiguration($partnerId);' . PHP_EOL .
'$config->serviceUrl = \'https://www.kaltura.com\';' . PHP_EOL .
'$client = new KalturaClient($config);' . PHP_EOL .
'$ks = $client->generateSession($adminSecret, $userId, KalturaSessionType::ADMIN, $partnerId);' . PHP_EOL .
'$client->setKs($ks);' . PHP_EOL .
'$filter = new KalturaMediaEntryFilter();' . PHP_EOL .
'$pager = new KalturaFilterPager();';
// PAGING
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) {
$pager->pageSize = intval($_GET['iDisplayLength']);
$pager->pageIndex = floor(intval($_GET['iDisplayStart']) / $pager->pageSize) + 1;
$codesample .= PHP_EOL . '$pager->pageSize = ' . intval($_GET['iDisplayLength']) . ';';
$codesample .= PHP_EOL . '$pager->pageIndex = ' . (floor(intval($_GET['iDisplayStart']) / $pager->pageSize) + 1) . ';';
}
/*
ORDERING
- Check KalturaMediaEntryOrderBy for more info.
- in Kaltura thumbnailUrl can't be sorted
- in Kaltura: MEDIATYPE_ASC / MEDIATYPE_DESC
- in Kaltura id can't be sorted
- in Kaltura: NAME_ASC / NAME_DESC
- in Kaltura description can't be sorted
- in Kaltura: UPDATED_AT_ASC / UPDATED_AT_DESC
- in Kaltura user Id can't be sorted
- Download is a generated cell, server can't sort according it cause we're creating it here...
iSortCol_ - The column id of the column to order
sSortDir_ - Should the column be desc or asc
*/
$aColumns = array( 'thumbnailUrl', 'mediaType', 'id', 'name', 'description', 'updatedAt', 'userId', 'download' );
if ( isset( $_GET['iSortCol_0'] ) )
{
for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
{
if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
{
$filter->orderBy = ($_GET['sSortDir_'.$i] == 'asc' ? '+' : '-') . $aColumns[ intval( $_GET['iSortCol_'.$i] ) ];
$codesample .= PHP_EOL . '$filter->orderBy = "'.($_GET['sSortDir_'.$i] == 'asc' ? '+' : '-') . $aColumns[ intval( $_GET['iSortCol_'.$i] ) ] . '"; //see KalturaMediaEntryOrderBy for available ordering methods';
break; //Kaltura can do only order by single field currently
}
}
}
// FILTERING
if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
{
$filter->freeText = $_GET['sSearch'];
$codesample .= PHP_EOL . '$filter->freeText = "' . $_GET['sSearch'] . '";';
}
// Status filter. see KalturaEntryStatus for list of status codes.
if ( isset($_GET['statusIn']) && $_GET['statusIn'] != "" ) {
$filter->statusIn = $_GET['statusIn'];
$codesample .= PHP_EOL . '$filter->statusIn = "' . $_GET['statusIn'] . '";';
}
//mediaTypeIn - See http://www.kaltura.com/api_v3/testmeDoc/index.php?object=KalturaMediaType
if ( isset($_GET['mediaTypeIn']) && $_GET['mediaTypeIn'] != "" ) {
$filter->mediaTypeIn = $_GET['mediaTypeIn'];
$codesample .= PHP_EOL . '$filter->mediaTypeIn = "' . $_GET['mediaTypeIn'] . '";';
}
// Execute the search (list) action
$filteredListResult = $client->media->listAction($filter, $pager);
$codesample .= PHP_EOL . '$filteredListResult = $client->media->listAction($filter, $pager);';
$codesample .= PHP_EOL . '// loop through the list and build the table:';
$codesample .= PHP_EOL . '$table = array();';
$codesample .= PHP_EOL . '$table[] = array("mediaType", "id", "name", "description", "updatedAt", "userId", "download");';
$codesample .= PHP_EOL . 'foreach ($filteredListResult->objects as $entry) {';
$codesample .= PHP_EOL . ' $row = array();';
$codesample .= PHP_EOL . ' //to learn more about thumbnail api see: https://knowledge.kaltura.com/kaltura-thumbnail-api';
$codesample .= PHP_EOL . ' //for the default thumbnail, can also use: $entry->thumbnailUrl;';
$codesample .= PHP_EOL . ' $row[] = \'<img src="https://cdnapisec.kaltura.com/p/\'.$partnerId.\'/thumbnail/entry_id/\'.$entry->id.\'/width/50/height/50/type/1/quality/100" />\'; ';
$codesample .= PHP_EOL . ' $row[] = $entry->mediaType;';
$codesample .= PHP_EOL . ' $row[] = $entry->id;';
$codesample .= PHP_EOL . ' $row[] = $entry->name;';
$codesample .= PHP_EOL . ' $row[] = $entry->description;';
$codesample .= PHP_EOL . ' $row[] = gmdate("m.d.y", $entry->updatedAt);';
$codesample .= PHP_EOL . ' $row[] = $entry->userId;';
$codesample .= PHP_EOL . ' if ($entry->mediaType == KalturaMediaType::VIDEO || $entry->mediaType == KalturaMediaType::AUDIO) {';
$codesample .= PHP_EOL . ' //to learn more about getting download url - https://knowledge.kaltura.com/faq/how-retrieve-download-or-streaming-url-using-api-calls';
$codesample .= PHP_EOL . ' $downloadUrl = \'https://www.kaltura.com/p/\'. $partnerId .\'/sp/0/playManifest/entryId/\'. $entry->id .\'/format/url/flavorParamId/0\';';
$codesample .= PHP_EOL . ' $row[] = \'<a href="\'.$downloadUrl.\'" target="_blank">Download</a>\';';
$codesample .= PHP_EOL . ' } else {';
$codesample .= PHP_EOL . ' $row[] = \'<a href="\'.$entry->dataUrl.\'" target="_blank" class="downloadlink"></a>\';';
$codesample .= PHP_EOL . ' }';
$codesample .= PHP_EOL . ' $table[] = $row;';
$codesample .= PHP_EOL . '}';
$codesample .= PHP_EOL . 'return $table;';
$output = array(
"codesample" => highlight_string('<?php' . PHP_EOL . $codesample . PHP_EOL . '?>', true),
"orderBy" => $filter->orderBy,
"iTotalRecords" => intval($filteredListResult->totalCount),
"iTotalDisplayRecords" => intval($filteredListResult->totalCount),
"aaData" => array()
);
if (isset($_GET['sEcho'])) {
$output["sEcho"] = intval($_GET['sEcho']);
}
foreach ($filteredListResult->objects as $entry) {
$row = array();
//to learn more about thumbnail api see: http://knowledge.kaltura.com/kaltura-thumbnail-api
//for the default thumbnail, can also use: $entry->thumbnailUrl;
$row[] = '<img src="https://cdnapisec.kaltura.com/p/'.$partnerId.'/thumbnail/entry_id/'.$entry->id.'/width/50/height/50/type/1/quality/100" />';
$row[] = '<span class="type type-'.$entry->mediaType.'"></span>';
$row[] = $entry->id;
$row[] = $entry->name;
$row[] = prepareDescription($entry->description);
$row[] = gmdate("m.d.y", $entry->updatedAt);
$row[] = tep_rewrite_email($entry->userId);
if ($entry->mediaType == KalturaMediaType::VIDEO || $entry->mediaType == KalturaMediaType::AUDIO) {
//to learn more about getting download url - http://knowledge.kaltura.com/faq/how-retrieve-download-or-streaming-url-using-api-calls
$row[] = '<a href="https://www.kaltura.com/p/'.$partnerId.'/sp/0/playManifest/entryId/'.$entry->id.'/format/url/flavorParamId/0" target="_blank" class="downloadlink"></a>';
} else {
$row[] = '<a href="'.$entry->dataUrl.'" target="_blank" class="downloadlink"></a>';
}
$row[]=$entry->duration.'';
$row[]=$entry->width.'';
$row[]=$entry->height.'';
$output['aaData'][] = $row;
}
echo json_encode( $output );
?>