tiki-kaltura_video.php 6.18 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
3 4 5
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
6 7
// $Id$

8 9
require_once 'tiki-setup.php';
require_once 'lib/videogals/videogallib.php';
10 11

try {
marclaporte's avatar
marclaporte committed
12
$smarty->assign('headtitle', tra('Kaltura Video'));
13

nagendra016's avatar
nagendra016 committed
14 15 16 17 18 19 20
$kentryType = "";
$videoId = array();
if(!empty($_REQUEST['mixId'])){	
	if(is_array($_REQUEST['mixId'])){
		$videoId = $_REQUEST['mixId'];
	}else{
		$videoId[0] = $_REQUEST['mixId'];
21
	}
nagendra016's avatar
nagendra016 committed
22
	$kentryType = "mix";
23 24
}

nagendra016's avatar
nagendra016 committed
25 26 27
if(!empty($_REQUEST['mediaId'])){	
	if(is_array($_REQUEST['mediaId'])){
		$videoId = $_REQUEST['mediaId'];
28
	}else{
nagendra016's avatar
nagendra016 committed
29
		$videoId[0] = $_REQUEST['mediaId'];
30
	}
nagendra016's avatar
nagendra016 committed
31
	$kentryType = "media";
32 33
}

nagendra016's avatar
nagendra016 committed
34
if(!empty($videoId) && isset($_REQUEST['action'])){
35 36

	$mode = $_REQUEST['action'];
37 38
	$smarty->assign('kmode',$mode);
	$smarty->assign('entryType',$kentryType);
39 40 41 42
	
	switch($mode){
	
	case 'remix':
43
		$access->check_permission(array('tiki_p_remix_videos'));
44
		$seflashVars = 'uid=' .$kuser.
45
			'&ks=' .$ksession. 
46 47
			'&partner_id=' . $prefs['partnerId'] .
			'&subp_id=' . $prefs['partnerId'] .'00'.
48
			'&backF=CloseClick'.
49 50
			'&saveF=SaveClick'.
			'&jsDelegate=kaeCallbacksObj';
51 52 53 54 55 56
		if (isset($_REQUEST['editor'])) {
			$editor = $_REQUEST['editor'];
		} else {
			$editor = $prefs['default_kaltura_editor'];
		}
		
57 58 59 60 61 62 63 64 65 66 67 68 69 70
		if($kentryType == "mix"){
			$seflashVars = $seflashVars.
				'&kshow_id=entry-' . $videoId[0].
				'&entry_id='. $videoId[0];	
		}
		if($kentryType == "media"){
			$kentry = $kclient->media->get($videoId[0]);
			$knewmixEntry = new KalturaMixEntry();
			$knewmixEntry->name = "Remix of ".$kentry->name;
			$knewmixEntry->editorType = 1; //SIMPLE
			$knewmixEntry = $kclient->mixing->add($knewmixEntry);
			$kclient->mixing->appendMediaEntry($knewmixEntry->id,$videoId[0]);

			header("Location: tiki-kaltura_video.php?action=remix&mixId=".$knewmixEntry->id);
71 72 73
		} else if (!isset($_REQUEST['editor'])) {
			$kentry = $kclient->mixing->get($videoId[0]);
			$editor = $kentry->editorType === 1 ? 'kse' : 'kae';	// not working - editor doesn't save editorType when you publish 
74
		}
75 76
		$smarty->assign_by_ref('seflashVars',$seflashVars);
		$smarty->assign_by_ref('editor',$editor);
nagendra016's avatar
nagendra016 committed
77
		$smarty->assign_by_ref('videoId',$videoId[0]);
78
		
79
		break;
nagendra016's avatar
nagendra016 committed
80
	case 'dupl':
81
		$access->check_permission(array('tiki_p_upload_videos'));
82 83
		if($kentryType == "mix"){
			$knewmixEntry = $kclient->mixing->cloneAction($videoId[0]);
nagendra016's avatar
nagendra016 committed
84 85 86 87 88 89
		}
		header ('Location: tiki-list_kaltura_entries.php');
		die;
		
		break;	
	case 'revert':
90
		$access->check_permission(array('tiki_p_admin_kaltura'));
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
		$koldentry = $kclient->mixing->get($videoId[0],$_REQUEST['version']);
		$koldentry = new KalturaMixEntry();
		$knewentry = new KalturaMixEntry();
		$knewentry->name = $koldentry->name;
		$knewentry->description = $koldentry->description;
		$knewentry->userId = $koldentry->userId;
		$knewentry->tags = $koldentry->tags;
		$knewentry->adminTags = $koldentry->adminTags;
		$knewentry->groupId = $koldentry->groupId;
		$knewentry->partnerData = $koldentry->partnerData;
		$knewentry->licenseType = $koldentry->licenseType;
		$knewentry->editorType = $koldentry->editorType;
		$knewentry->dataContent =$koldentry->dataContent;
		$knewentry = $kclient->mixing->update($koldentry->id,$knewentry);
		$smarty->assign_by_ref('videoId',$knewentry->id);
		$smarty->assign_by_ref('videoInfo',$knewentry);
107 108
		break;
	case 'delete':
109
		$access->check_permission(array('tiki_p_delete_videos'));
110 111 112 113
		$access->check_authenticity();
		if($kentryType == "media"){
			foreach( $videoId as $vi ) {
				$kclient->media->delete($vi);
114 115
			}
		}
116 117 118 119 120
		if($kentryType == "mix"){
			foreach( $videoId as $vi ) {
				$kclient->mixing->delete($vi);
			}					
		}	
121 122
		header ('Location: tiki-list_kaltura_entries.php');
		die;
123 124
		break;
	case 'download':
125
		$access->check_permission(array('tiki_p_download_videos'));
126
		$kres = $kclient->mixing->requestFlattening($videoId[0],'flv');
nagendra016's avatar
nagendra016 committed
127

128 129
		header ('Location: tiki-kaltura_video.php?videoId='.$videoId[0]);
		die;
nagendra016's avatar
nagendra016 committed
130 131
		break;
	case 'edit':
132
		$access->check_permission(array('tiki_p_edit_videos'));
133 134 135 136
		if ($_REQUEST['update']){
			$ksession = $kclient->session->start( $prefs['adminSecret'], $kuser, $SESSION_ADMIN, $prefs['partnerId'], 86400, 'edit:*' );
			$kclient->setKs($ksession);
		}
137 138 139
		if($kentryType == "mix"){
			$kentry = $kclient->mixing->get($videoId[0]);
			
nagendra016's avatar
nagendra016 committed
140
			if($_REQUEST['update']){
141
				$kentry = new KalturaPlayableEntry();
142 143 144
				$kentry->name = $_REQUEST['name'];
				$kentry->description = $_REQUEST['description'];
				$kentry->tags = $_REQUEST['tags'];
145
				$kentry->editorType = $_REQUEST['editor'] === 'kse' ? 1 : 2;
146 147
				$kentry->adminTags = $_REQUEST['adminTags'];
				$knewentry = $kclient->mixing->update($videoId[0],$kentry);
nagendra016's avatar
nagendra016 committed
148 149
			}
		}
150 151
		if($kentryType == "media"){
			$kentry = $kclient->media->get($videoId[0]);
152
			
153
			if($_REQUEST['update']){
154
				$kentry = new KalturaPlayableEntry();
155 156 157 158
				$kentry->name = $_REQUEST['name'];
				$kentry->description = $_REQUEST['description'];
				$kentry->tags = $_REQUEST['tags'];
				$kentry->adminTags = $_REQUEST['adminTags'];
159

160 161 162 163 164 165 166 167 168
				$knewentry = $kclient->media->update($videoId[0],$kentry);
			}
		}
		if($_REQUEST['update']){
			header ('Location: tiki-kaltura_video.php?'.$kentryType.'Id='.$videoId[0]);
			die;
		}
		$smarty->assign_by_ref('videoId',$videoId[0]);
		$smarty->assign_by_ref('videoInfo',$kentry);
169 170 171 172 173 174 175 176 177
		break;
	case 'default':
		$smarty->assign('msg', tra("Incorrect param"));
		$smarty->display('error.tpl');
		die;
		
	}
		
}else{
nagendra016's avatar
nagendra016 committed
178
	if(isset($videoId[0])){
179
		$access->check_permission(array('tiki_p_view_videos'));
180
		$smarty->assign('kmode', 'view');
181 182
		if($kentryType == "mix"){
			$kentry = $kclient->mixing->get($videoId[0]);
183
		}
nagendra016's avatar
nagendra016 committed
184
	
185 186 187 188 189
		if($kentryType == "media"){
			$kentry = $kclient->media->get($videoId[0]);	
		}
		$smarty->assign_by_ref('videoId',$videoId[0]);
		$smarty->assign_by_ref('videoInfo',$kentry);
190
	}
nagendra016's avatar
nagendra016 committed
191
	$smarty->assign_by_ref('entryType',$kentryType);
192 193 194
}

// Display the template
195 196
$smarty->assign('mid','tiki-kaltura_video.tpl');
$smarty->display("tiki.tpl");
197 198

} catch( Exception $e ) {
199
	$access->display_error( '', tr('Communication error'), 500, true, tr('Invalid response provided by the Kaltura server. Please retry.') . '<br /><em>' . $e->getMessage() . '</em>' );
200
}