Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 82 lines (82 sloc) 3.255 kb
f2bd5a6 Thomas Huzij Binded the button to the select field and revised RemoveTags.php to
Tubebaum authored
1 <?php
2 require_once("kalturaConfig.php");
2fd2ddc Thomas Huzij Cleaned up the code and added comments
Tubebaum authored
3 //Retrieves the array of tags from a cached file created by getTagList.php
f2bd5a6 Thomas Huzij Binded the button to the select field and revised RemoveTags.php to
Tubebaum authored
4 $tagArray = unserialize(file_get_contents(TAG_CACHE));
2fd2ddc Thomas Huzij Cleaned up the code and added comments
Tubebaum authored
5 //Includes the client library and starts a Kaltura session to access the API
6 //More informatation about this process can be found at
7 //http://knowledge.kaltura.com/introduction-kaltura-client-libraries
8 require_once('lib/php5/KalturaClient.php');
f2bd5a6 Thomas Huzij Binded the button to the select field and revised RemoveTags.php to
Tubebaum authored
9 $config = new KalturaConfiguration(PARTNER_ID);
10 $config->serviceUrl = 'http://www.kaltura.com/';
11 $client = new KalturaClient($config);
12 $ks = $client->generateSession(ADMIN_SECRET, USER_ID, KalturaSessionType::ADMIN, PARTNER_ID);
13 $client->setKs($ks);
14 //Formats the tags correctly
15 $tags = $_REQUEST['tags'];
3a952f8 Thomas Huzij Blocked empty submissions for adding and removing tags
Tubebaum authored
16 //Removes the tags from the cache
1cbbd44 Thomas Huzij Block page from loading if kalturaConfig.php has not been modified
Tubebaum authored
17 foreach($tags as $index => $deleteTag) {
3a952f8 Thomas Huzij Blocked empty submissions for adding and removing tags
Tubebaum authored
18 unset($tagArray[$deleteTag]);
1cbbd44 Thomas Huzij Block page from loading if kalturaConfig.php has not been modified
Tubebaum authored
19 }
20 function escapeChar($input)
21 {
22 $input = '\\'.$input[0];
23 return $input;
24 }
ed0aab4 Thomas Huzij Fixed a bug in removing tags
Tubebaum authored
25 $tagString = implode(', ', $tags);
26 $tagString = preg_replace_callback('|[#-+]|','escapeChar',$tagString);
27 $tagString = preg_replace_callback('|[--/]|','escapeChar',$tagString);
1cbbd44 Thomas Huzij Block page from loading if kalturaConfig.php has not been modified
Tubebaum authored
28 $tagString = preg_replace_callback('|!|','escapeChar',$tagString);
29 $tagString = preg_replace_callback('|"|','escapeChar',$tagString);
30 $tagString = preg_replace_callback('|-|','escapeChar',$tagString);
31 $tagString = preg_replace_callback('|\\/|','escapeChar',$tagString);
3a952f8 Thomas Huzij Blocked empty submissions for adding and removing tags
Tubebaum authored
32 $pager = new KalturaFilterPager();
33 $pageSize = 500;
34 $pager->pageSize = $pageSize;
35 $lastCreatedAt = 0;
36 $lastEntryIds = "";
37 $cont = true;
38 while($cont) {
39 //Instead of using a page index, the entries are retrieved by creation date
40 //This is the only way to ensure that the server retrieves all of the entries
41 $filter = new KalturaMediaEntryFilter();
42 $filter->orderBy = "-createdAt";
43 $filter->tagsMultiLikeOr = $tagString;
44 //Ignores entries that have already been parsed
45 if($lastCreatedAt != 0)
46 $filter->createdAtLessThanOrEqual = $lastCreatedAt;
47 if($lastEntryIds != "")
48 $filter->idNotIn = $lastEntryIds;
49 $results = $client->media->listAction($filter, $pager);
50 //If no entries are retrieved the loop may end
51 if(count($results->objects) == 0) {
52 $cont = false;
f2bd5a6 Thomas Huzij Binded the button to the select field and revised RemoveTags.php to
Tubebaum authored
53 }
3a952f8 Thomas Huzij Blocked empty submissions for adding and removing tags
Tubebaum authored
54 //For each entry in the server, the requested tags are removed
55 foreach($results->objects as $place => $entry) {
56 //Retrieves the old tags
57 $oldTags = explode(',', $entry->tags);
58 foreach($oldTags as $index => $tag) {
59 $oldTags[$index] = trim($tag);
d38ad1f Thomas Huzij Fixed empty submissions
Tubebaum authored
60 }
3a952f8 Thomas Huzij Blocked empty submissions for adding and removing tags
Tubebaum authored
61 //Deletes the appropriate tags
62 foreach($tags as $tag) {
63 if(in_array($tag, $oldTags))
64 unset($oldTags[array_search($tag, $oldTags)]);
d38ad1f Thomas Huzij Fixed empty submissions
Tubebaum authored
65 }
3a952f8 Thomas Huzij Blocked empty submissions for adding and removing tags
Tubebaum authored
66 //Updates the corresponding media entry with the new list of tags
67 $joinedTags = implode(', ', $oldTags);
68 $mediaEntry = new KalturaMediaEntry();
69 $mediaEntry->tags = $joinedTags;
70 $entryId = $results->objects[$place]->id;
71 $updateResults = $client->media->update($entryId, $mediaEntry);
72 //Keeps a tally of which creation dates were examined
73 //and which entry ids have already been seen
74 if($lastCreatedAt != $entry->createdAt)
75 $lastEntryIds = "";
76 if($lastEntryIds != "")
77 $lastEntryIds .= ",";
78 $lastEntryIds .= $entry->id;
79 $lastCreatedAt = $entry->createdAt;
d38ad1f Thomas Huzij Fixed empty submissions
Tubebaum authored
80 }
81 }
3a952f8 Thomas Huzij Blocked empty submissions for adding and removing tags
Tubebaum authored
82 file_put_contents(TAG_CACHE, serialize($tagArray));
Something went wrong with that request. Please try again.