Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Final Draft

  • Loading branch information...
commit 6f527f6fca9b8608453ce75e7e24064140a8f902 1 parent f2bd5a6
@Tubebaum Tubebaum authored
View
10 .buildpath
@@ -1,5 +1,5 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<buildpath>
- <buildpathentry kind="src" path=""/>
- <buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
-</buildpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<buildpath>
+ <buildpathentry kind="src" path=""/>
+ <buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
+</buildpath>
View
32 .settings/.jsdtscope
@@ -1,16 +1,16 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="">
- <attributes>
- <attribute name="provider" value="org.eclipse.wst.jsdt.web.core.internal.project.ModuleSourcePathProvider"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
- <attributes>
- <attribute name="hide" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
- <classpathentry kind="output" path=""/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="">
+ <attributes>
+ <attribute name="provider" value="org.eclipse.wst.jsdt.web.core.internal.project.ModuleSourcePathProvider"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
+ <attributes>
+ <attribute name="hide" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
+ <classpathentry kind="output" path=""/>
+</classpath>
View
4 .settings/org.eclipse.php.core.prefs
@@ -1,2 +1,2 @@
-eclipse.preferences.version=1
-include_path=0;/gallery
+eclipse.preferences.version=1
+include_path=0;/gallery
View
34 addNewTags.php
@@ -1,18 +1,18 @@
-<?php
-require_once("kalturaConfig.php");
-require_once('php5/KalturaClient.php');
-$config = new KalturaConfiguration(PARTNER_ID);
-$config->serviceUrl = 'http://www.kaltura.com/';
-$client = new KalturaClient($config);
-$ks = $client->generateSession(ADMIN_SECRET, USER_ID, KalturaSessionType::ADMIN, PARTNER_ID);
-$client->setKs($ks);
-$tagArray = unserialize(file_get_contents(TAG_CACHE));
-$tags = explode(',', $_REQUEST["tags"]);
-//Adds each new tag to the tags cache
-foreach($tags as $tag) {
- $tag = strtolower(trim($tag));
- if(!array_key_exists($tag, $tagArray) && $tag !== "") {
- $tagArray[$tag] = 0;
- }
-}
+<?php
+require_once("kalturaConfig.php");
+require_once('php5/KalturaClient.php');
+$config = new KalturaConfiguration(PARTNER_ID);
+$config->serviceUrl = 'http://www.kaltura.com/';
+$client = new KalturaClient($config);
+$ks = $client->generateSession(ADMIN_SECRET, USER_ID, KalturaSessionType::ADMIN, PARTNER_ID);
+$client->setKs($ks);
+$tagArray = unserialize(file_get_contents(TAG_CACHE));
+$tags = explode(',', $_REQUEST["tags"]);
+//Adds each new tag to the tags cache
+foreach($tags as $tag) {
+ $tag = strtolower(trim($tag));
+ if(!array_key_exists($tag, $tagArray) && $tag !== "") {
+ $tagArray[$tag] = 0;
+ }
+}
file_put_contents(TAG_CACHE, serialize($tagArray));
View
190 getTagList.php
@@ -1,96 +1,96 @@
-<?php
-require_once("kalturaConfig.php");
-$cachetime = 5 * 60; //Cache time is 5 minutes
-//Only updates the Existing Tags list every time the cache time expires
-if (!file_exists(TAG_CACHE) || (time() - $cachetime > filemtime(TAG_CACHE))) {
- require_once('php5/KalturaClient.php');
- $config = new KalturaConfiguration(PARTNER_ID);
- $config->serviceUrl = 'http://www.kaltura.com/';
- $client = new KalturaClient($config);
- $ks = $client->generateSession(ADMIN_SECRET, USER_ID, KalturaSessionType::ADMIN, PARTNER_ID);
- $client->setKs($ks);
-
- $pager = new KalturaFilterPager();
- $pageSize = 500;
- $pager->pageSize = $pageSize;
- $lastCreatedAt = 0;
- $lastEntryIds = "";
- $cont = true;
- while($cont) {
- $filter = new KalturaMediaEntryFilter();
- $filter->orderBy = "-createdAt";
- if($lastCreatedAt != 0)
- $filter->createdAtLessThanOrEqual = $lastCreatedAt;
- if($lastEntryIds != "")
- $filter->idNotIn = $lastEntryIds;
- $results = $client->media->listAction($filter, $pager);
- if(count($results->objects) == 0) {
- $cont = false;
- }
- $entryIds = "";
- foreach($results->objects as $entry) {
- $tags = explode(',', $entry->tags);
- foreach ($tags as $tag) {
- $tag = trim($tag);
- if ($tag == "") continue;
- //If the tag has already been discovered, increment its frequency
- if (isset($tagArray[$tag]))
- ++$tagArray[$tag];
- //Otherwise, add the new tag to the array
- else
- $tagArray[$tag] = 1;
-
- if($lastCreatedAt != $entry->createdAt)
- $lastEntryIds = "";
- if($lastEntryIds != "")
- $lastEntryIds .= ",";
- $lastEntryIds .= $entry->id;
- $lastCreatedAt = $entry->createdAt;
- }
- }
- }
-// $filter = new KalturaMediaEntryFilter();
-// $filter->orderBy = KalturaMediaEntryOrderBy::CREATED_AT_DESC;
-// $pager->pageIndex = 1;
-// $results = $client->media->listAction($filter, $pager);
-// $count = $results->totalCount;
-// $endPage = (int)($count / $pageSize);
-// $endPage += ($count % $pageSize == 0) ? 0 : 1;
-// $tagArray = array();
-// //Stores each tag name as its own index and keeps a tally of how many times that tag is found
-// for($pageNum = 1; $pageNum <= $endPage; ++$pageNum) {
-// $pager->pageIndex = $pageNum;
-// if($pageNum > 1)
-// $results = $client->media->listAction($filter, $pager);
-// foreach ($results->objects as $entry) {
-// $tags = explode(',', $entry->tags);
-// foreach ($tags as $tag) {
-// $tag = trim($tag);
-// if ($tag == "") continue;
-// //If the tag has already been discovered, increment its frequency
-// if (isset($tagArray[$tag]))
-// ++$tagArray[$tag];
-// //Otherwise, add the new tag to the array
-// else
-// $tagArray[$tag] = 1;
-// }
-// }
-// }
- //Stores the array of tags in a file that can be retrieved immediately for faster loading time
- $tagArrayString = serialize($tagArray);
- file_put_contents(TAG_CACHE, $tagArrayString);
- //Creates a string of every tag and its respective frequeny and returns it
- $tagString = "";
- foreach($tagArray as $tag => $tagCount) $tagString .= $tag.' ('.$tagCount.'), ';
- echo substr($tagString, 0, -2);
-}
-//If the cache time has not passed yet, do not recreate the tag array
-//Instead use the array that has been stored
-else {
- $tagString = file_get_contents(TAG_CACHE);
- $tagArray = unserialize($tagString);
- //Creates a string of every tag and its respective frequeny and returns it
- $tagString = "";
- foreach($tagArray as $tag => $tagCount) $tagString .= $tag.' ('.$tagCount.'), ';
- echo substr($tagString, 0, -2);
+<?php
+require_once("kalturaConfig.php");
+$cachetime = 5 * 60; //Cache time is 5 minutes
+//Only updates the Existing Tags list every time the cache time expires
+if (!file_exists(TAG_CACHE) || (time() - $cachetime > filemtime(TAG_CACHE))) {
+ require_once('php5/KalturaClient.php');
+ $config = new KalturaConfiguration(PARTNER_ID);
+ $config->serviceUrl = 'http://www.kaltura.com/';
+ $client = new KalturaClient($config);
+ $ks = $client->generateSession(ADMIN_SECRET, USER_ID, KalturaSessionType::ADMIN, PARTNER_ID);
+ $client->setKs($ks);
+
+ $pager = new KalturaFilterPager();
+ $pageSize = 500;
+ $pager->pageSize = $pageSize;
+ $lastCreatedAt = 0;
+ $lastEntryIds = "";
+ $cont = true;
+ while($cont) {
+ $filter = new KalturaMediaEntryFilter();
+ $filter->orderBy = "-createdAt";
+ if($lastCreatedAt != 0)
+ $filter->createdAtLessThanOrEqual = $lastCreatedAt;
+ if($lastEntryIds != "")
+ $filter->idNotIn = $lastEntryIds;
+ $results = $client->media->listAction($filter, $pager);
+ if(count($results->objects) == 0) {
+ $cont = false;
+ }
+ $entryIds = "";
+ foreach($results->objects as $entry) {
+ $tags = explode(',', $entry->tags);
+ foreach ($tags as $tag) {
+ $tag = trim($tag);
+ if ($tag == "") continue;
+ //If the tag has already been discovered, increment its frequency
+ if (isset($tagArray[$tag]))
+ ++$tagArray[$tag];
+ //Otherwise, add the new tag to the array
+ else
+ $tagArray[$tag] = 1;
+
+ if($lastCreatedAt != $entry->createdAt)
+ $lastEntryIds = "";
+ if($lastEntryIds != "")
+ $lastEntryIds .= ",";
+ $lastEntryIds .= $entry->id;
+ $lastCreatedAt = $entry->createdAt;
+ }
+ }
+ }
+// $filter = new KalturaMediaEntryFilter();
+// $filter->orderBy = KalturaMediaEntryOrderBy::CREATED_AT_DESC;
+// $pager->pageIndex = 1;
+// $results = $client->media->listAction($filter, $pager);
+// $count = $results->totalCount;
+// $endPage = (int)($count / $pageSize);
+// $endPage += ($count % $pageSize == 0) ? 0 : 1;
+// $tagArray = array();
+// //Stores each tag name as its own index and keeps a tally of how many times that tag is found
+// for($pageNum = 1; $pageNum <= $endPage; ++$pageNum) {
+// $pager->pageIndex = $pageNum;
+// if($pageNum > 1)
+// $results = $client->media->listAction($filter, $pager);
+// foreach ($results->objects as $entry) {
+// $tags = explode(',', $entry->tags);
+// foreach ($tags as $tag) {
+// $tag = trim($tag);
+// if ($tag == "") continue;
+// //If the tag has already been discovered, increment its frequency
+// if (isset($tagArray[$tag]))
+// ++$tagArray[$tag];
+// //Otherwise, add the new tag to the array
+// else
+// $tagArray[$tag] = 1;
+// }
+// }
+// }
+ //Stores the array of tags in a file that can be retrieved immediately for faster loading time
+ $tagArrayString = serialize($tagArray);
+ file_put_contents(TAG_CACHE, $tagArrayString);
+ //Creates a string of every tag and its respective frequeny and returns it
+ $tagString = "";
+ foreach($tagArray as $tag => $tagCount) $tagString .= $tag.' ('.$tagCount.'), ';
+ echo substr($tagString, 0, -2);
+}
+//If the cache time has not passed yet, do not recreate the tag array
+//Instead use the array that has been stored
+else {
+ $tagString = file_get_contents(TAG_CACHE);
+ $tagArray = unserialize($tagString);
+ //Creates a string of every tag and its respective frequeny and returns it
+ $tagString = "";
+ foreach($tagArray as $tag => $tagCount) $tagString .= $tag.' ('.$tagCount.'), ';
+ echo substr($tagString, 0, -2);
}
View
8 kalturaConfig.sample.php
@@ -1,5 +1,5 @@
-<?php
-define("PARTNER_ID",xxxx);
-define("ADMIN_SECRET",'xxxx');
-define("USER_ID",'tagsManager');
+<?php
+define("PARTNER_ID",xxxx);
+define("ADMIN_SECRET",'xxxx');
+define("USER_ID",'tagsManager');
define("TAG_CACHE", 'tagArray.txt');
View
70 php5/KalturaClient.php
@@ -4190,56 +4190,56 @@ class KalturaClient extends KalturaClientBase
protected $apiVersion = '3.1.4';
/**
- * Manage access control profiles
+ * Manage access control profiles
* @var KalturaAccessControlProfileService
*/
public $accessControlProfile = null;
/**
* Add & Manage Access Controls
- * DEPRECATED - use accessControlProfile service instead
+ * DEPRECATED - use accessControlProfile service instead
* @var KalturaAccessControlService
*/
public $accessControl = null;
/**
- * Manage details for the administrative user
+ * Manage details for the administrative user
* @var KalturaAdminUserService
*/
public $adminUser = null;
/**
- * Base Entry Service
+ * Base Entry Service
* @var KalturaBaseEntryService
*/
public $baseEntry = null;
/**
- * Bulk upload service is used to upload & manage bulk uploads using CSV files
+ * Bulk upload service is used to upload & manage bulk uploads using CSV files
* @var KalturaBulkUploadService
*/
public $bulkUpload = null;
/**
- * Add & Manage Categories
+ * Add & Manage Categories
* @var KalturaCategoryService
*/
public $category = null;
/**
- * Manage the connection between Conversion Profiles and Asset Params
+ * Manage the connection between Conversion Profiles and Asset Params
* @var KalturaConversionProfileAssetParamsService
*/
public $conversionProfileAssetParams = null;
/**
- * Add & Manage Conversion Profiles
+ * Add & Manage Conversion Profiles
* @var KalturaConversionProfileService
*/
public $conversionProfile = null;
/**
- * Data service lets you manage data content (textual content)
+ * Data service lets you manage data content (textual content)
* @var KalturaDataService
*/
public $data = null;
@@ -4252,81 +4252,81 @@ class KalturaClient extends KalturaClientBase
public $document = null;
/**
- * EmailIngestionProfile service lets you manage email ingestion profile records
+ * EmailIngestionProfile service lets you manage email ingestion profile records
* @var KalturaEmailIngestionProfileService
*/
public $EmailIngestionProfile = null;
/**
- * Retrieve information and invoke actions on Flavor Asset
+ * Retrieve information and invoke actions on Flavor Asset
* @var KalturaFlavorAssetService
*/
public $flavorAsset = null;
/**
- * Add & Manage Flavor Params
+ * Add & Manage Flavor Params
* @var KalturaFlavorParamsService
*/
public $flavorParams = null;
/**
- * Live Stream service lets you manage live stream channels
+ * Live Stream service lets you manage live stream channels
* @var KalturaLiveStreamService
*/
public $liveStream = null;
/**
- * Media Info service
+ * Media Info service
* @var KalturaMediaInfoService
*/
public $mediaInfo = null;
/**
- * Media service lets you upload and manage media files (images / videos & audio)
+ * Media service lets you upload and manage media files (images / videos & audio)
* @var KalturaMediaService
*/
public $media = null;
/**
* A Mix is an XML unique format invented by Kaltura, it allows the user to create a mix of videos and images, in and out points, transitions, text overlays, soundtrack, effects and much more...
- * Mixing service lets you create a new mix, manage its metadata and make basic manipulations.
+ * Mixing service lets you create a new mix, manage its metadata and make basic manipulations.
* @var KalturaMixingService
*/
public $mixing = null;
/**
- * Notification Service
+ * Notification Service
* @var KalturaNotificationService
*/
public $notification = null;
/**
- * partner service allows you to change/manage your partner personal details and settings as well
+ * partner service allows you to change/manage your partner personal details and settings as well
* @var KalturaPartnerService
*/
public $partner = null;
/**
- * PermissionItem service lets you create and manage permission items
+ * PermissionItem service lets you create and manage permission items
* @var KalturaPermissionItemService
*/
public $permissionItem = null;
/**
- * Permission service lets you create and manage user permissions
+ * Permission service lets you create and manage user permissions
* @var KalturaPermissionService
*/
public $permission = null;
/**
* Playlist service lets you create,manage and play your playlists
- * Playlists could be static (containing a fixed list of entries) or dynamic (baseed on a filter)
+ * Playlists could be static (containing a fixed list of entries) or dynamic (baseed on a filter)
* @var KalturaPlaylistService
*/
public $playlist = null;
/**
- * api for getting reports data by the report type and some inputFilter
+ * api for getting reports data by the report type and some inputFilter
* @var KalturaReportService
*/
public $report = null;
@@ -4340,56 +4340,56 @@ class KalturaClient extends KalturaClientBase
/**
* Search service allows you to search for media in various media providers
- * This service is being used mostly by the CW component
+ * This service is being used mostly by the CW component
* @var KalturaSearchService
*/
public $search = null;
/**
- * Session service
+ * Session service
* @var KalturaSessionService
*/
public $session = null;
/**
- * Stats Service
+ * Stats Service
* @var KalturaStatsService
*/
public $stats = null;
/**
- * Storage Profiles service
+ * Storage Profiles service
* @var KalturaStorageProfileService
*/
public $storageProfile = null;
/**
- * Add & Manage Syndication Feeds
+ * Add & Manage Syndication Feeds
* @var KalturaSyndicationFeedService
*/
public $syndicationFeed = null;
/**
- * System service is used for internal system helpers & to retrieve system level information
+ * System service is used for internal system helpers & to retrieve system level information
* @var KalturaSystemService
*/
public $system = null;
/**
- * Retrieve information and invoke actions on Thumb Asset
+ * Retrieve information and invoke actions on Thumb Asset
* @var KalturaThumbAssetService
*/
public $thumbAsset = null;
/**
- * Add & Manage Thumb Params
+ * Add & Manage Thumb Params
* @var KalturaThumbParamsService
*/
public $thumbParams = null;
/**
* UiConf service lets you create and manage your UIConfs for the various flash components
- * This service is used by the KMC-ApplicationStudio
+ * This service is used by the KMC-ApplicationStudio
* @var KalturaUiConfService
*/
public $uiConf = null;
@@ -4407,26 +4407,26 @@ class KalturaClient extends KalturaClientBase
public $uploadToken = null;
/**
- * UserRole service lets you create and manage user roles
+ * UserRole service lets you create and manage user roles
* @var KalturaUserRoleService
*/
public $userRole = null;
/**
* Manage partner users on Kaltura's side
- * The userId in kaltura is the unique Id in the partner's system, and the [partnerId,Id] couple are unique key in kaltura's DB
+ * The userId in kaltura is the unique Id in the partner's system, and the [partnerId,Id] couple are unique key in kaltura's DB
* @var KalturaUserService
*/
public $user = null;
/**
- * widget service for full widget management
+ * widget service for full widget management
* @var KalturaWidgetService
*/
public $widget = null;
/**
- * Internal Service is used for actions that are used internally in Kaltura applications and might be changed in the future without any notice.
+ * Internal Service is used for actions that are used internally in Kaltura applications and might be changed in the future without any notice.
* @var KalturaXInternalService
*/
public $xInternal = null;
View
1,976 php5/KalturaClientBase.php
@@ -1,1012 +1,1012 @@
-<?php
-// ===================================================================================================
-// _ __ _ _
-// | |/ /__ _| | |_ _ _ _ _ __ _
-// | ' </ _` | | _| || | '_/ _` |
-// |_|\_\__,_|_|\__|\_,_|_| \__,_|
-//
-// This file is part of the Kaltura Collaborative Media Suite which allows users
-// to do with audio, video, and animation what Wiki platfroms allow them to do with
-// text.
-//
-// Copyright (C) 2006-2011 Kaltura Inc.
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-//
-// @ignore
-// ===================================================================================================
-
-/**
+<?php
+// ===================================================================================================
+// _ __ _ _
+// | |/ /__ _| | |_ _ _ _ _ __ _
+// | ' </ _` | | _| || | '_/ _` |
+// |_|\_\__,_|_|\__|\_,_|_| \__,_|
+//
+// This file is part of the Kaltura Collaborative Media Suite which allows users
+// to do with audio, video, and animation what Wiki platfroms allow them to do with
+// text.
+//
+// Copyright (C) 2006-2011 Kaltura Inc.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// @ignore
+// ===================================================================================================
+
+/**
* @package External
* @subpackage Kaltura
- */
-class MultiRequestSubResult
-{
- function __construct($value)
- {
- $this->value = $value;
- }
-
- function __toString()
- {
- return '{' . $this->value . '}';
- }
-
- function __get($name)
- {
- return new MultiRequestSubResult($this->value . ':' . $name);
- }
-}
-
-/**
+ */
+class MultiRequestSubResult
+{
+ function __construct($value)
+ {
+ $this->value = $value;
+ }
+
+ function __toString()
+ {
+ return '{' . $this->value . '}';
+ }
+
+ function __get($name)
+ {
+ return new MultiRequestSubResult($this->value . ':' . $name);
+ }
+}
+
+/**
* @package External
* @subpackage Kaltura
- */
-class KalturaNull
-{
- private static $instance;
-
- private function __construct()
- {
-
- }
-
- public static function getInstance()
- {
- if (!isset(self::$instance)) {
- $c = __CLASS__;
- self::$instance = new $c();
- }
- return self::$instance;
- }
-
- function __toString()
- {
- return '';
- }
-
-}
-
-/**
+ */
+class KalturaNull
+{
+ private static $instance;
+
+ private function __construct()
+ {
+
+ }
+
+ public static function getInstance()
+ {
+ if (!isset(self::$instance)) {
+ $c = __CLASS__;
+ self::$instance = new $c();
+ }
+ return self::$instance;
+ }
+
+ function __toString()
+ {
+ return '';
+ }
+
+}
+
+/**
* @package External
* @subpackage Kaltura
- */
-class KalturaClientBase
-{
- const KALTURA_SERVICE_FORMAT_JSON = 1;
- const KALTURA_SERVICE_FORMAT_XML = 2;
- const KALTURA_SERVICE_FORMAT_PHP = 3;
-
- /**
- * @var string
- */
- protected $apiVersion = null;
-
- /**
- * @var KalturaConfiguration
- */
- protected $config;
-
- /**
- * @var string
- */
- private $ks;
-
- /**
- * @var boolean
- */
- private $shouldLog = false;
-
- /**
- * @var bool
- */
- private $isMultiRequest = false;
-
- /**
- * @var unknown_type
- */
- private $callsQueue = array();
-
- /**
- * Array of all plugin services
- *
- * @var array<KalturaServiceBase>
- */
- protected $pluginServices = array();
-
- /**
- * @var Array of response headers
- */
- private $responseHeaders = array();
-
- public function __get($serviceName)
- {
- if(isset($this->pluginServices[$serviceName]))
- return $this->pluginServices[$serviceName];
-
- return null;
- }
-
- /**
- * Kaltura client constructor
- *
- * @param KalturaConfiguration $config
- */
- public function __construct(KalturaConfiguration $config)
- {
- $this->config = $config;
-
- $logger = $this->config->getLogger();
- if ($logger)
- {
- $this->shouldLog = true;
- }
-
- // load all plugins
- $pluginsFolder = realpath(dirname(__FILE__)) . '/KalturaPlugins';
- if(is_dir($pluginsFolder))
- {
- $dir = dir($pluginsFolder);
- while (false !== $fileName = $dir->read())
- {
- $matches = null;
- if(preg_match('/^([^.]+).php$/', $fileName, $matches))
- {
- require_once("$pluginsFolder/$fileName");
-
- $pluginClass = $matches[1];
- if(!class_exists($pluginClass) || !in_array('IKalturaClientPlugin', class_implements($pluginClass)))
- continue;
-
- $plugin = call_user_func(array($pluginClass, 'get'), $this);
- if(!($plugin instanceof IKalturaClientPlugin))
- continue;
-
- $pluginName = $plugin->getName();
- $services = $plugin->getServices();
- foreach($services as $serviceName => $service)
- {
- $service->setClient($this);
- $this->pluginServices[$serviceName] = $service;
- }
- }
- }
- }
- }
-
- /* Store response headers into array */
- public function readHeader($ch, $string)
- {
- array_push($this->responseHeaders, $string);
- return strlen($string);
- }
-
- /* Retrive response headers */
- public function getResponseHeaders()
- {
- return $this->responseHeaders;
- }
-
- public function getServeUrl()
- {
- if (count($this->callsQueue) != 1)
- return null;
-
- $params = array();
- $files = array();
- $this->log("service url: [" . $this->config->serviceUrl . "]");
-
- // append the basic params
- $this->addParam($params, "apiVersion", $this->apiVersion);
- $this->addParam($params, "format", $this->config->format);
- $this->addParam($params, "clientTag", $this->config->clientTag);
-
- $call = $this->callsQueue[0];
- $this->callsQueue = array();
- $this->isMultiRequest = false;
-
- $params = array_merge($params, $call->params);
- $signature = $this->signature($params);
- $this->addParam($params, "kalsig", $signature);
-
- $url = $this->config->serviceUrl . "/api_v3/index.php?service={$call->service}&action={$call->action}";
- $url .= '&' . http_build_query($params);
- $this->log("Returned url [$url]");
- return $url;
- }
-
- public function queueServiceActionCall($service, $action, $params = array(), $files = array())
- {
- // in start session partner id is optional (default -1). if partner id was not set, use the one in the config
- if (!isset($params["partnerId"]) || $params["partnerId"] === -1)
- $params["partnerId"] = $this->config->partnerId;
-
- $this->addParam($params, "ks", $this->ks);
-
- $call = new KalturaServiceActionCall($service, $action, $params, $files);
- $this->callsQueue[] = $call;
- }
-
- /**
- * Call all API service that are in queue
- *
- * @return unknown
- */
- public function doQueue()
- {
- if (count($this->callsQueue) == 0)
- {
- $this->isMultiRequest = false;
- return null;
- }
-
- $startTime = microtime(true);
-
- $params = array();
- $files = array();
- $this->log("service url: [" . $this->config->serviceUrl . "]");
-
- // append the basic params
- $this->addParam($params, "apiVersion", $this->apiVersion);
- $this->addParam($params, "format", $this->config->format);
- $this->addParam($params, "clientTag", $this->config->clientTag);
-
- $url = $this->config->serviceUrl."/api_v3/index.php?service=";
- if ($this->isMultiRequest)
- {
- $url .= "multirequest";
- $i = 1;
- foreach ($this->callsQueue as $call)
- {
- $callParams = $call->getParamsForMultiRequest($i);
- $callFiles = $call->getFilesForMultiRequest($i);
- $params = array_merge($params, $callParams);
- $files = array_merge($files, $callFiles);
- $i++;
- }
- }
- else
- {
- $call = $this->callsQueue[0];
- $url .= $call->service."&action=".$call->action;
- $params = array_merge($params, $call->params);
- $files = $call->files;
- }
-
- // reset
- $this->callsQueue = array();
- $this->isMultiRequest = false;
-
- $signature = $this->signature($params);
- $this->addParam($params, "kalsig", $signature);
-
- list($postResult, $error) = $this->doHttpRequest($url, $params, $files);
-
- if ($error)
- {
- throw new KalturaClientException($error, KalturaClientException::ERROR_GENERIC);
- }
- else
- {
-// if(strlen($postResult) > 1024)
-// $this->log("result (serialized): " . strlen($postResult) . " bytes");
-// else
- $this->log("result (serialized): " . $postResult);
-
- if ($this->config->format == self::KALTURA_SERVICE_FORMAT_PHP)
- {
- $result = @unserialize($postResult);
-
- if ($result === false && serialize(false) !== $postResult)
- {
- throw new KalturaClientException("failed to unserialize server result\n$postResult", KalturaClientException::ERROR_UNSERIALIZE_FAILED);
- }
- $dump = print_r($result, true);
-// if(strlen($dump) < 1024)
- $this->log("result (object dump): " . $dump);
- }
- else
- {
- throw new KalturaClientException("unsupported format: $postResult", KalturaClientException::ERROR_FORMAT_NOT_SUPPORTED);
- }
- }
-
- $endTime = microtime (true);
-
- $this->log("execution time for [".$url."]: [" . ($endTime - $startTime) . "]");
-
- return $result;
- }
-
- /**
- * Sign array of parameters
- *
- * @param array $params
- * @return string
- */
- private function signature($params)
- {
- ksort($params);
- $str = "";
- foreach ($params as $k => $v)
- {
- $str .= $k.$v;
- }
- return md5($str);
- }
-
- /**
- * Send http request by using curl (if available) or php stream_context
- *
- * @param string $url
- * @param parameters $params
- * @return array of result and error
- */
- private function doHttpRequest($url, $params = array(), $files = array())
- {
- if (function_exists('curl_init'))
- return $this->doCurl($url, $params, $files);
- else
- return $this->doPostRequest($url, $params, $files);
- }
-
- /**
- * Curl HTTP POST Request
- *
- * @param string $url
- * @param array $params
- * @return array of result and error
- */
- private function doCurl($url, $params = array(), $files = array())
- {
- $this->responseHeaders = array();
- $cookies = array();
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- if (count($files) > 0)
- {
- foreach($files as &$file)
- $file = "@".$file; // let curl know its a file
- curl_setopt($ch, CURLOPT_POSTFIELDS, array_merge($params, $files));
- }
- else
- {
- $opt = http_build_query($params, null, "&");
- $this->log("curl: $url&$opt");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $opt);
- }
- curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_USERAGENT, $this->config->userAgent);
- if (count($files) > 0)
- curl_setopt($ch, CURLOPT_TIMEOUT, 0);
- else
- curl_setopt($ch, CURLOPT_TIMEOUT, $this->config->curlTimeout);
-
- if ($this->config->startZendDebuggerSession === true)
- {
- $zendDebuggerParams = $this->getZendDebuggerParams($url);
- $cookies = array_merge($cookies, $zendDebuggerParams);
- }
-
- if (count($cookies) > 0)
- {
- $cookiesStr = http_build_query($cookies, null, '; ');
- curl_setopt($ch, CURLOPT_COOKIE, $cookiesStr);
- }
-
- if (isset($this->config->proxyHost)) {
- curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
- curl_setopt($ch, CURLOPT_PROXY, $this->config->proxyHost);
- if (isset($this->config->proxyPort)) {
- curl_setopt($ch, CURLOPT_PROXYPORT, $this->config->proxyPort);
- }
- if (isset($this->config->proxyUser)) {
- curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->config->proxyUser.':'.$this->config->proxyPassword);
- }
- if (isset($this->config->proxyType) && $this->config->proxyType === 'SOCKS5') {
- curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
- }
- }
-
- // Set SSL verification
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->config->verifySSL);
-
- // Set custom headers
- curl_setopt($ch, CURLOPT_HTTPHEADER, $this->config->requestHeaders );
-
- // Save response headers
- curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'readHeader') );
-
- $result = curl_exec($ch);
- $curlError = curl_error($ch);
- curl_close($ch);
- return array($result, $curlError);
- }
-
- /**
- * HTTP stream context request
- *
- * @param string $url
- * @param array $params
- * @return array of result and error
- */
- private function doPostRequest($url, $params = array(), $files = array())
- {
- if (count($files) > 0)
- throw new KalturaClientException("Uploading files is not supported with stream context http request, please use curl", KalturaClientException::ERROR_UPLOAD_NOT_SUPPORTED);
-
- $formattedData = http_build_query($params , "", "&");
- $params = array('http' => array(
- "method" => "POST",
- "User-Agent: " . $this->config->userAgent . "\r\n".
- "Accept-language: en\r\n".
- "Content-type: application/x-www-form-urlencoded\r\n",
- "content" => $formattedData
- ));
-
- if (isset($this->config->proxyType) && $this->config->proxyType === 'SOCKS5') {
- throw new KalturaClientException("Cannot use SOCKS5 without curl installed.", KalturaClientException::ERROR_CONNECTION_FAILED);
- }
- if (isset($this->config->proxyHost)) {
- $proxyhost = 'tcp://' . $this->config->proxyHost;
- if (isset($this->config->proxyPort)) {
- $proxyhost = $proxyhost . ":" . $this->config->proxyPort;
- }
- $params['http']['proxy'] = $proxyhost;
- $params['http']['request_fulluri'] = true;
- if (isset($this->config->proxyUser)) {
- $auth = base64_encode($this->config->proxyUser.':'.$this->config->proxyPassword);
- $params['http']['header'] = 'Proxy-Authorization: Basic ' . $auth;
- }
- }
-
- $ctx = stream_context_create($params);
- $fp = @fopen($url, 'rb', false, $ctx);
- if (!$fp) {
- $phpErrorMsg = "";
- throw new KalturaClientException("Problem with $url, $phpErrorMsg", KalturaClientException::ERROR_CONNECTION_FAILED);
- }
- $response = @stream_get_contents($fp);
- if ($response === false) {
- throw new KalturaClientException("Problem reading data from $url, $phpErrorMsg", KalturaClientException::ERROR_READ_FAILED);
- }
- return array($response, '');
- }
-
- /**
- * @return string
- */
- public function getKs()
- {
- return $this->ks;
- }
-
- /**
- * @param string $ks
- */
- public function setKs($ks)
- {
- $this->ks = $ks;
- }
-
- /**
- * @return KalturaConfiguration
- */
- public function getConfig()
- {
- return $this->config;
- }
-
- /**
- * @param KalturaConfiguration $config
- */
- public function setConfig(KalturaConfiguration $config)
- {
- $this->config = $config;
-
- $logger = $this->config->getLogger();
- if ($logger instanceof IKalturaLogger)
- {
- $this->shouldLog = true;
- }
- }
-
- /**
- * Add parameter to array of parameters that is passed by reference
- *
- * @param arrat $params
- * @param string $paramName
- * @param string $paramValue
- */
- public function addParam(&$params, $paramName, $paramValue)
- {
- if ($paramValue === null)
- return;
-
- if ($paramValue instanceof KalturaNull) {
- $params[$paramName . '__null'] = '';
- return;
- }
-
- if(is_object($paramValue) && $paramValue instanceof KalturaObjectBase)
- {
- $this->addParam($params, "$paramName:objectType", get_class($paramValue));
- foreach($paramValue as $prop => $val)
- $this->addParam($params, "$paramName:$prop", $val);
-
- return;
- }
-
- if(!is_array($paramValue))
- {
- $params[$paramName] = (string)$paramValue;
- return;
- }
-
- if ($paramValue)
- {
- foreach($paramValue as $subParamName => $subParamValue)
- $this->addParam($params, "$paramName:$subParamName", $subParamValue);
- }
- else
- {
- $this->addParam($params, "$paramName:-", "");
- }
- }
-
- /**
- * Validate the result object and throw exception if its an error
- *
- * @param object $resultObject
- */
- public function throwExceptionIfError($resultObject)
- {
- if ($this->isError($resultObject))
- {
- throw new KalturaException($resultObject["message"], $resultObject["code"]);
- }
- }
-
- /**
- * Checks whether the result object is an error
- *
- * @param object $resultObject
- */
- public function isError($resultObject)
- {
- return (is_array($resultObject) && isset($resultObject["message"]) && isset($resultObject["code"]));
- }
-
- /**
- * Validate that the passed object type is of the expected type
- *
- * @param unknown_type $resultObject
- * @param unknown_type $objectType
- */
- public function validateObjectType($resultObject, $objectType)
- {
- if (is_object($resultObject))
- {
- if (!($resultObject instanceof $objectType))
- throw new KalturaClientException("Invalid object type", KalturaClientException::ERROR_INVALID_OBJECT_TYPE);
- }
- else if (gettype($resultObject) !== "NULL" && gettype($resultObject) !== $objectType)
- {
- throw new KalturaClientException("Invalid object type", KalturaClientException::ERROR_INVALID_OBJECT_TYPE);
- }
- }
-
- public function startMultiRequest()
- {
- $this->isMultiRequest = true;
- }
-
- public function doMultiRequest()
- {
- return $this->doQueue();
- }
-
- public function isMultiRequest()
- {
- return $this->isMultiRequest;
- }
-
- public function getMultiRequestQueueSize()
- {
- return count($this->callsQueue);
- }
-
- public function getMultiRequestResult()
- {
- return new MultiRequestSubResult($this->getMultiRequestQueueSize() . ':result');
- }
-
- /**
- * @param string $msg
- */
- protected function log($msg)
- {
- if ($this->shouldLog)
- $this->config->getLogger()->log($msg);
- }
-
- /**
- * Return a list of parameter used to a new start debug on the destination server api
- * @link http://kb.zend.com/index.php?View=entry&EntryID=434
- * @param $url
- */
- protected function getZendDebuggerParams($url)
- {
- $params = array();
- $passThruParams = array('debug_host',
- 'debug_fastfile',
- 'debug_port',
- 'start_debug',
- 'send_debug_header',
- 'send_sess_end',
- 'debug_jit',
- 'debug_stop',
- 'use_remote');
-
- foreach($passThruParams as $param)
- {
- if (isset($_COOKIE[$param]))
- $params[$param] = $_COOKIE[$param];
- }
-
- $params['original_url'] = $url;
- $params['debug_session_id'] = microtime(true); // to create a new debug session
-
- return $params;
- }
-
- public function generateSession($adminSecretForSigning, $userId, $type, $partnerId, $expiry = 86400, $privileges = '')
- {
- $rand = rand(0, 32000);
- $expiry = time()+$expiry;
- $fields = array (
- $partnerId ,
- $partnerId ,
- $expiry ,
- $type,
- $rand ,
- $userId ,
- $privileges
- );
- $info = implode ( ";" , $fields );
-
- $signature = $this->hash ( $adminSecretForSigning , $info );
- $strToHash = $signature . "|" . $info ;
- $encoded_str = base64_encode( $strToHash );
-
- return $encoded_str;
- }
-
- private function hash ( $salt , $str )
- {
- return sha1($salt.$str);
- }
-
- /**
- * @return KalturaNull
- */
- public static function getKalturaNullValue()
- {
-
- return KalturaNull::getInstance();
- }
-
-}
-
-/**
+ */
+class KalturaClientBase
+{
+ const KALTURA_SERVICE_FORMAT_JSON = 1;
+ const KALTURA_SERVICE_FORMAT_XML = 2;
+ const KALTURA_SERVICE_FORMAT_PHP = 3;
+
+ /**
+ * @var string
+ */
+ protected $apiVersion = null;
+
+ /**
+ * @var KalturaConfiguration
+ */
+ protected $config;
+
+ /**
+ * @var string
+ */
+ private $ks;
+
+ /**
+ * @var boolean
+ */
+ private $shouldLog = false;
+
+ /**
+ * @var bool
+ */
+ private $isMultiRequest = false;
+
+ /**
+ * @var unknown_type
+ */
+ private $callsQueue = array();
+
+ /**
+ * Array of all plugin services
+ *
+ * @var array<KalturaServiceBase>
+ */
+ protected $pluginServices = array();
+
+ /**
+ * @var Array of response headers
+ */
+ private $responseHeaders = array();
+
+ public function __get($serviceName)
+ {
+ if(isset($this->pluginServices[$serviceName]))
+ return $this->pluginServices[$serviceName];
+
+ return null;
+ }
+
+ /**
+ * Kaltura client constructor
+ *
+ * @param KalturaConfiguration $config
+ */
+ public function __construct(KalturaConfiguration $config)
+ {
+ $this->config = $config;
+
+ $logger = $this->config->getLogger();
+ if ($logger)
+ {
+ $this->shouldLog = true;
+ }
+
+ // load all plugins
+ $pluginsFolder = realpath(dirname(__FILE__)) . '/KalturaPlugins';
+ if(is_dir($pluginsFolder))
+ {
+ $dir = dir($pluginsFolder);
+ while (false !== $fileName = $dir->read())
+ {
+ $matches = null;
+ if(preg_match('/^([^.]+).php$/', $fileName, $matches))
+ {
+ require_once("$pluginsFolder/$fileName");
+
+ $pluginClass = $matches[1];
+ if(!class_exists($pluginClass) || !in_array('IKalturaClientPlugin', class_implements($pluginClass)))
+ continue;
+
+ $plugin = call_user_func(array($pluginClass, 'get'), $this);
+ if(!($plugin instanceof IKalturaClientPlugin))
+ continue;
+
+ $pluginName = $plugin->getName();
+ $services = $plugin->getServices();
+ foreach($services as $serviceName => $service)
+ {
+ $service->setClient($this);
+ $this->pluginServices[$serviceName] = $service;
+ }
+ }
+ }
+ }
+ }
+
+ /* Store response headers into array */
+ public function readHeader($ch, $string)
+ {
+ array_push($this->responseHeaders, $string);
+ return strlen($string);
+ }
+
+ /* Retrive response headers */
+ public function getResponseHeaders()
+ {
+ return $this->responseHeaders;
+ }
+
+ public function getServeUrl()
+ {
+ if (count($this->callsQueue) != 1)
+ return null;
+
+ $params = array();
+ $files = array();
+ $this->log("service url: [" . $this->config->serviceUrl . "]");
+
+ // append the basic params
+ $this->addParam($params, "apiVersion", $this->apiVersion);
+ $this->addParam($params, "format", $this->config->format);
+ $this->addParam($params, "clientTag", $this->config->clientTag);
+
+ $call = $this->callsQueue[0];
+ $this->callsQueue = array();
+ $this->isMultiRequest = false;
+
+ $params = array_merge($params, $call->params);
+ $signature = $this->signature($params);
+ $this->addParam($params, "kalsig", $signature);
+
+ $url = $this->config->serviceUrl . "/api_v3/index.php?service={$call->service}&action={$call->action}";
+ $url .= '&' . http_build_query($params);
+ $this->log("Returned url [$url]");
+ return $url;
+ }
+
+ public function queueServiceActionCall($service, $action, $params = array(), $files = array())
+ {
+ // in start session partner id is optional (default -1). if partner id was not set, use the one in the config
+ if (!isset($params["partnerId"]) || $params["partnerId"] === -1)
+ $params["partnerId"] = $this->config->partnerId;
+
+ $this->addParam($params, "ks", $this->ks);
+
+ $call = new KalturaServiceActionCall($service, $action, $params, $files);
+ $this->callsQueue[] = $call;
+ }
+
+ /**
+ * Call all API service that are in queue
+ *
+ * @return unknown
+ */
+ public function doQueue()
+ {
+ if (count($this->callsQueue) == 0)
+ {
+ $this->isMultiRequest = false;
+ return null;
+ }
+
+ $startTime = microtime(true);
+
+ $params = array();
+ $files = array();
+ $this->log("service url: [" . $this->config->serviceUrl . "]");
+
+ // append the basic params
+ $this->addParam($params, "apiVersion", $this->apiVersion);
+ $this->addParam($params, "format", $this->config->format);
+ $this->addParam($params, "clientTag", $this->config->clientTag);
+
+ $url = $this->config->serviceUrl."/api_v3/index.php?service=";
+ if ($this->isMultiRequest)
+ {
+ $url .= "multirequest";
+ $i = 1;
+ foreach ($this->callsQueue as $call)
+ {
+ $callParams = $call->getParamsForMultiRequest($i);
+ $callFiles = $call->getFilesForMultiRequest($i);
+ $params = array_merge($params, $callParams);
+ $files = array_merge($files, $callFiles);
+ $i++;
+ }
+ }
+ else
+ {
+ $call = $this->callsQueue[0];
+ $url .= $call->service."&action=".$call->action;
+ $params = array_merge($params, $call->params);
+ $files = $call->files;
+ }
+
+ // reset
+ $this->callsQueue = array();
+ $this->isMultiRequest = false;
+
+ $signature = $this->signature($params);
+ $this->addParam($params, "kalsig", $signature);
+
+ list($postResult, $error) = $this->doHttpRequest($url, $params, $files);
+
+ if ($error)
+ {
+ throw new KalturaClientException($error, KalturaClientException::ERROR_GENERIC);
+ }
+ else
+ {
+// if(strlen($postResult) > 1024)
+// $this->log("result (serialized): " . strlen($postResult) . " bytes");
+// else
+ $this->log("result (serialized): " . $postResult);
+
+ if ($this->config->format == self::KALTURA_SERVICE_FORMAT_PHP)
+ {
+ $result = @unserialize($postResult);
+
+ if ($result === false && serialize(false) !== $postResult)
+ {
+ throw new KalturaClientException("failed to unserialize server result\n$postResult", KalturaClientException::ERROR_UNSERIALIZE_FAILED);
+ }
+ $dump = print_r($result, true);
+// if(strlen($dump) < 1024)
+ $this->log("result (object dump): " . $dump);
+ }
+ else
+ {
+ throw new KalturaClientException("unsupported format: $postResult", KalturaClientException::ERROR_FORMAT_NOT_SUPPORTED);
+ }
+ }
+
+ $endTime = microtime (true);
+
+ $this->log("execution time for [".$url."]: [" . ($endTime - $startTime) . "]");
+
+ return $result;
+ }
+
+ /**
+ * Sign array of parameters
+ *
+ * @param array $params
+ * @return string
+ */
+ private function signature($params)
+ {
+ ksort($params);
+ $str = "";
+ foreach ($params as $k => $v)
+ {
+ $str .= $k.$v;
+ }
+ return md5($str);
+ }
+
+ /**
+ * Send http request by using curl (if available) or php stream_context
+ *
+ * @param string $url
+ * @param parameters $params
+ * @return array of result and error
+ */
+ private function doHttpRequest($url, $params = array(), $files = array())
+ {
+ if (function_exists('curl_init'))
+ return $this->doCurl($url, $params, $files);
+ else
+ return $this->doPostRequest($url, $params, $files);
+ }
+
+ /**
+ * Curl HTTP POST Request
+ *
+ * @param string $url
+ * @param array $params
+ * @return array of result and error
+ */
+ private function doCurl($url, $params = array(), $files = array())
+ {
+ $this->responseHeaders = array();
+ $cookies = array();
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ if (count($files) > 0)
+ {
+ foreach($files as &$file)
+ $file = "@".$file; // let curl know its a file
+ curl_setopt($ch, CURLOPT_POSTFIELDS, array_merge($params, $files));
+ }
+ else
+ {
+ $opt = http_build_query($params, null, "&");
+ $this->log("curl: $url&$opt");
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $opt);
+ }
+ curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_USERAGENT, $this->config->userAgent);
+ if (count($files) > 0)
+ curl_setopt($ch, CURLOPT_TIMEOUT, 0);
+ else
+ curl_setopt($ch, CURLOPT_TIMEOUT, $this->config->curlTimeout);
+
+ if ($this->config->startZendDebuggerSession === true)
+ {
+ $zendDebuggerParams = $this->getZendDebuggerParams($url);
+ $cookies = array_merge($cookies, $zendDebuggerParams);
+ }
+
+ if (count($cookies) > 0)
+ {
+ $cookiesStr = http_build_query($cookies, null, '; ');
+ curl_setopt($ch, CURLOPT_COOKIE, $cookiesStr);
+ }
+
+ if (isset($this->config->proxyHost)) {
+ curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
+ curl_setopt($ch, CURLOPT_PROXY, $this->config->proxyHost);
+ if (isset($this->config->proxyPort)) {
+ curl_setopt($ch, CURLOPT_PROXYPORT, $this->config->proxyPort);
+ }
+ if (isset($this->config->proxyUser)) {
+ curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->config->proxyUser.':'.$this->config->proxyPassword);
+ }
+ if (isset($this->config->proxyType) && $this->config->proxyType === 'SOCKS5') {
+ curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+ }
+ }
+
+ // Set SSL verification
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->config->verifySSL);
+
+ // Set custom headers
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $this->config->requestHeaders );
+
+ // Save response headers
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'readHeader') );
+
+ $result = curl_exec($ch);
+ $curlError = curl_error($ch);
+ curl_close($ch);
+ return array($result, $curlError);
+ }
+
+ /**
+ * HTTP stream context request
+ *
+ * @param string $url
+ * @param array $params
+ * @return array of result and error
+ */
+ private function doPostRequest($url, $params = array(), $files = array())
+ {
+ if (count($files) > 0)
+ throw new KalturaClientException("Uploading files is not supported with stream context http request, please use curl", KalturaClientException::ERROR_UPLOAD_NOT_SUPPORTED);
+
+ $formattedData = http_build_query($params , "", "&");
+ $params = array('http' => array(
+ "method" => "POST",
+ "User-Agent: " . $this->config->userAgent . "\r\n".
+ "Accept-language: en\r\n".
+ "Content-type: application/x-www-form-urlencoded\r\n",
+ "content" => $formattedData
+ ));
+
+ if (isset($this->config->proxyType) && $this->config->proxyType === 'SOCKS5') {
+ throw new KalturaClientException("Cannot use SOCKS5 without curl installed.", KalturaClientException::ERROR_CONNECTION_FAILED);
+ }
+ if (isset($this->config->proxyHost)) {
+ $proxyhost = 'tcp://' . $this->config->proxyHost;
+ if (isset($this->config->proxyPort)) {
+ $proxyhost = $proxyhost . ":" . $this->config->proxyPort;
+ }
+ $params['http']['proxy'] = $proxyhost;
+ $params['http']['request_fulluri'] = true;
+ if (isset($this->config->proxyUser)) {
+ $auth = base64_encode($this->config->proxyUser.':'.$this->config->proxyPassword);
+ $params['http']['header'] = 'Proxy-Authorization: Basic ' . $auth;
+ }
+ }
+
+ $ctx = stream_context_create($params);
+ $fp = @fopen($url, 'rb', false, $ctx);
+ if (!$fp) {
+ $phpErrorMsg = "";
+ throw new KalturaClientException("Problem with $url, $phpErrorMsg", KalturaClientException::ERROR_CONNECTION_FAILED);
+ }
+ $response = @stream_get_contents($fp);
+ if ($response === false) {
+ throw new KalturaClientException("Problem reading data from $url, $phpErrorMsg", KalturaClientException::ERROR_READ_FAILED);
+ }
+ return array($response, '');
+ }
+
+ /**
+ * @return string
+ */
+ public function getKs()
+ {
+ return $this->ks;
+ }
+
+ /**
+ * @param string $ks
+ */
+ public function setKs($ks)
+ {
+ $this->ks = $ks;
+ }
+
+ /**
+ * @return KalturaConfiguration
+ */
+ public function getConfig()
+ {
+ return $this->config;
+ }
+
+ /**
+ * @param KalturaConfiguration $config
+ */
+ public function setConfig(KalturaConfiguration $config)
+ {
+ $this->config = $config;
+
+ $logger = $this->config->getLogger();
+ if ($logger instanceof IKalturaLogger)
+ {
+ $this->shouldLog = true;
+ }
+ }
+
+ /**
+ * Add parameter to array of parameters that is passed by reference
+ *
+ * @param arrat $params
+ * @param string $paramName
+ * @param string $paramValue
+ */
+ public function addParam(&$params, $paramName, $paramValue)
+ {
+ if ($paramValue === null)
+ return;
+
+ if ($paramValue instanceof KalturaNull) {
+ $params[$paramName . '__null'] = '';
+ return;
+ }
+
+ if(is_object($paramValue) && $paramValue instanceof KalturaObjectBase)
+ {
+ $this->addParam($params, "$paramName:objectType", get_class($paramValue));
+ foreach($paramValue as $prop => $val)
+ $this->addParam($params, "$paramName:$prop", $val);
+
+ return;
+ }
+
+ if(!is_array($paramValue))
+ {
+ $params[$paramName] = (string)$paramValue;
+ return;
+ }
+
+ if ($paramValue)
+ {
+ foreach($paramValue as $subParamName => $subParamValue)
+ $this->addParam($params, "$paramName:$subParamName", $subParamValue);
+ }
+ else
+ {
+ $this->addParam($params, "$paramName:-", "");
+ }
+ }
+
+ /**
+ * Validate the result object and throw exception if its an error
+ *
+ * @param object $resultObject
+ */
+ public function throwExceptionIfError($resultObject)
+ {
+ if ($this->isError($resultObject))
+ {
+ throw new KalturaException($resultObject["message"], $resultObject["code"]);
+ }
+ }
+
+ /**
+ * Checks whether the result object is an error
+ *
+ * @param object $resultObject
+ */
+ public function isError($resultObject)
+ {
+ return (is_array($resultObject) && isset($resultObject["message"]) && isset($resultObject["code"]));
+ }
+
+ /**
+ * Validate that the passed object type is of the expected type
+ *
+ * @param unknown_type $resultObject
+ * @param unknown_type $objectType
+ */
+ public function validateObjectType($resultObject, $objectType)
+ {
+ if (is_object($resultObject))
+ {
+ if (!($resultObject instanceof $objectType))
+ throw new KalturaClientException("Invalid object type", KalturaClientException::ERROR_INVALID_OBJECT_TYPE);
+ }
+ else if (gettype($resultObject) !== "NULL" && gettype($resultObject) !== $objectType)
+ {
+ throw new KalturaClientException("Invalid object type", KalturaClientException::ERROR_INVALID_OBJECT_TYPE);
+ }
+ }
+
+ public function startMultiRequest()
+ {
+ $this->isMultiRequest = true;
+ }
+
+ public function doMultiRequest()
+ {
+ return $this->doQueue();
+ }
+
+ public function isMultiRequest()
+ {
+ return $this->isMultiRequest;
+ }
+
+ public function getMultiRequestQueueSize()
+ {
+ return count($this->callsQueue);
+ }
+
+ public function getMultiRequestResult()
+ {
+ return new MultiRequestSubResult($this->getMultiRequestQueueSize() . ':result');
+ }
+
+ /**
+ * @param string $msg
+ */
+ protected function log($msg)
+ {
+ if ($this->shouldLog)
+ $this->config->getLogger()->log($msg);
+ }
+
+ /**
+ * Return a list of parameter used to a new start debug on the destination server api
+ * @link http://kb.zend.com/index.php?View=entry&EntryID=434
+ * @param $url
+ */
+ protected function getZendDebuggerParams($url)
+ {
+ $params = array();
+ $passThruParams = array('debug_host',
+ 'debug_fastfile',
+ 'debug_port',
+ 'start_debug',
+ 'send_debug_header',
+ 'send_sess_end',
+ 'debug_jit',
+ 'debug_stop',
+ 'use_remote');
+
+ foreach($passThruParams as $param)
+ {
+ if (isset($_COOKIE[$param]))
+ $params[$param] = $_COOKIE[$param];
+ }
+
+ $params['original_url'] = $url;
+ $params['debug_session_id'] = microtime(true); // to create a new debug session
+
+ return $params;
+ }
+
+ public function generateSession($adminSecretForSigning, $userId, $type, $partnerId, $expiry = 86400, $privileges = '')
+ {
+ $rand = rand(0, 32000);
+ $expiry = time()+$expiry;
+ $fields = array (
+ $partnerId ,
+ $partnerId ,
+ $expiry ,
+ $type,
+ $rand ,
+ $userId ,
+ $privileges
+ );
+ $info = implode ( ";" , $fields );
+
+ $signature = $this->hash ( $adminSecretForSigning , $info );
+ $strToHash = $signature . "|" . $info ;
+ $encoded_str = base64_encode( $strToHash );
+
+ return $encoded_str;
+ }
+
+ private function hash ( $salt , $str )
+ {
+ return sha1($salt.$str);
+ }
+
+ /**
+ * @return KalturaNull
+ */
+ public static function getKalturaNullValue()
+ {
+
+ return KalturaNull::getInstance();
+ }
+
+}
+
+/**
* @package External
* @subpackage Kaltura
- */
-interface IKalturaClientPlugin
-{
- /**
- * @return KalturaClientPlugin
- */
- public static function get(KalturaClient $client);
-
- /**
- * @return array<KalturaServiceBase>
- */
- public function getServices();
-
- /**
- * @return string
- */
- public function getName();
-}
-
-/**
+ */
+interface IKalturaClientPlugin
+{
+ /**
+ * @return KalturaClientPlugin
+ */
+ public static function get(KalturaClient $client);
+
+ /**
+ * @return array<KalturaServiceBase>
+ */
+ public function getServices();
+
+ /**
+ * @return string
+ */
+ public function getName();
+}
+
+/**
* @package External
* @subpackage Kaltura
- */
-abstract class KalturaClientPlugin implements IKalturaClientPlugin
-{
- protected function __construct(KalturaClient $client)
- {
-
- }
-}
-
-/**
+ */
+abstract class KalturaClientPlugin implements IKalturaClientPlugin
+{
+ protected function __construct(KalturaClient $client)
+ {
+
+ }
+}
+
+/**
* @package External
* @subpackage Kaltura
- */
-class KalturaServiceActionCall
-{
- /**
- * @var string
- */
- public $service;
-
- /**
- * @var string
- */
- public $action;
-
-
- /**
- * @var array
- */
- public $params;
-
- /**
- * @var array
- */
- public $files;
-
- /**
- * Contruct new Kaltura service action call, if params array contain sub arrays (for objects), it will be flattened
- *
- * @param string $service
- * @param string $action
- * @param array $params
- * @param array $files
- */
- public function __construct($service, $action, $params = array(), $files = array())
- {
- $this->service = $service;
- $this->action = $action;
- $this->params = $this->parseParams($params);
- $this->files = $files;
- }
-
- /**
- * Parse params array and sub arrays (for objects)
- *
- * @param array $params
- */
- public function parseParams(array $params)
- {
- $newParams = array();
- foreach($params as $key => $val)
- {
- if (is_array($val))
- {
- $newParams[$key] = $this->parseParams($val);
- }
- else
- {
- $newParams[$key] = $val;
- }
- }
- return $newParams;
- }
-
- /**
- * Return the parameters for a multi request
- *
- * @param int $multiRequestIndex
- */
- public function getParamsForMultiRequest($multiRequestIndex)
- {
- $multiRequestParams = array();
- $multiRequestParams[$multiRequestIndex.":service"] = $this->service;
- $multiRequestParams[$multiRequestIndex.":action"] = $this->action;
- foreach($this->params as $key => $val)
- {
- $multiRequestParams[$multiRequestIndex.":".$key] = $val;
- }
- return $multiRequestParams;
- }
-
- /**
- * Return the parameters for a multi request
- *
- * @param int $multiRequestIndex
- */
- public function getFilesForMultiRequest($multiRequestIndex)
- {
- $multiRequestParams = array();
- foreach($this->files as $key => $val)
- {
- $multiRequestParams[$multiRequestIndex.":".$key] = $val;
- }
- return $multiRequestParams;
- }
-}
-
-/**
- * Abstract base class for all client services
- *
+ */
+class KalturaServiceActionCall
+{
+ /**
+ * @var string
+ */
+ public $service;
+
+ /**
+ * @var string
+ */
+ public $action;
+
+
+ /**
+ * @var array
+ */
+ public $params;
+
+ /**
+ * @var array
+ */
+ public $files;
+
+ /**
+ * Contruct new Kaltura service action call, if params array contain sub arrays (for objects), it will be flattened
+ *
+ * @param string $service
+ * @param string $action
+ * @param array $params
+ * @param array $files
+ */
+ public function __construct($service, $action, $params = array(), $files = array())
+ {
+ $this->service = $service;
+ $this->action = $action;
+ $this->params = $this->parseParams($params);
+ $this->files = $files;
+ }