/** * @param string $string * @return string */ private static function stringToSafeXml($string) { $string = @iconv('utf-8', 'utf-8', $string); $partially_safe = kString::xmlEncode($string); $safe = str_replace(array('*', '/', '[', ']'), '', $partially_safe); return $safe; }
public function validateForSubmission(EntryDistribution $entryDistribution, $action) { $validationErrors = parent::validateForSubmission($entryDistribution, $action); $maxLengthFields = array(YouTubeDistributionField::MEDIA_DESCRIPTION => self::MEDIA_DESCRIPTION_MAXIMUM_LENGTH, YouTubeDistributionField::MEDIA_TITLE => self::MEDIA_TITLE_MAXIMUM_LENGTH, YouTubeDistributionField::WEB_METADATA_CUSTOM_ID => self::METADATA_CUSTOM_ID_MAXIMUM_LENGTH, YouTubeDistributionField::MOVIE_METADATA_CUSTOM_ID => self::METADATA_CUSTOM_ID_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_CUSTOM_ID => self::METADATA_CUSTOM_ID_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_EPISODE => self::TV_METADATA_EPISODE_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_EPISODE_TITLE => self::TV_METADATA_EPISODE_TITLE_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_SEASON => self::TV_METADATA_SEASON_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_SHOW_TITLE => self::TV_METADATA_SHOW_TITLE_MAXIMUM_LENGTH, YouTubeDistributionField::TV_METADATA_TMS_ID => self::TV_METADATA_TMS_ID_MAXIMUM_LENGTH, YouTubeDistributionField::MOVIE_METADATA_TITLE => self::MOVIE_METADATA_TITLE_MAXIMUM_LENGTH, YouTubeDistributionField::MOVIE_METADATA_TMS_ID => self::MOVIE_METADATA_TMS_ID_MAXIMUM_LENGTH); $inListOrNullFields = array(YouTubeDistributionField::MEDIA_RATING => explode(',', self::MEDIA_RATING_VALID_VALUES), YouTubeDistributionField::ALLOW_COMMENTS => explode(',', self::ALLOW_COMMENTS_VALID_VALUES), YouTubeDistributionField::ALLOW_EMBEDDING => explode(',', self::ALLOW_EMBEDDING_VALID_VALUES), YouTubeDistributionField::ALLOW_RATINGS => explode(',', self::ALLOW_RATINGS_VALID_VALUES), YouTubeDistributionField::ALLOW_RESPONSES => explode(',', self::ALLOW_RESPONSES_VALID_VALUES), YouTubeDistributionField::ADVERTISING_INVIDEO => explode(',', self::ADVERTISING_INVIDEO_VALID_VALUES), YouTubeDistributionField::ADVERTISING_ADSENSE_FOR_VIDEO => explode(',', self::ADVERTISING_ADSENSE_FOR_VIDEO_VALUES), YouTubeDistributionField::DISTRIBUTION_RESTRICTION_DISTRIBUTION_RULE => explode(',', self::DISTRIBUTION_RESTRICTION_DISTRIBUTION_RULE_VALUES), YouTubeDistributionField::URGENT_REFERENCE_FILE => explode(',', self::URGENT_REFERENCE_FILE_VALUES), YouTubeDistributionField::KEEP_FINGERPRINT => explode(',', self::KEEP_FINGERPRINT_VALUES)); $allFieldValues = $this->getAllFieldValues($entryDistribution); if (!$allFieldValues || !is_array($allFieldValues)) { KalturaLog::err('Error getting field values from entry distribution id [' . $entryDistribution->getId() . '] profile id [' . $this->getId() . ']'); return $validationErrors; } $validationErrors = array_merge($validationErrors, $this->validateMaxLength($maxLengthFields, $allFieldValues, $action)); $validationErrors = array_merge($validationErrors, $this->validateInListOrNull($inListOrNullFields, $allFieldValues, $action)); $fieldName = YouTubeDistributionField::NOTIFICATION_EMAIL; $value = $allFieldValues[$fieldName]; //multiple email support $values = explode(' ', $value); foreach ($values as $val) { if (!is_null($val) && !kString::isEmailString($val)) { $errorMsg = $this->getUserFriendlyFieldName($fieldName) . ' value must be an email string [value:' . $val . ']'; $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, $this->getUserFriendlyFieldName($fieldName)); $validationError->setValidationErrorType(DistributionValidationErrorType::CUSTOM_ERROR); $validationError->setValidationErrorParam($errorMsg); $validationErrors[] = $validationError; } } //TODO: check if MEDIA_CATEGORY is a valid YouTube category according to YouTube's XML. return $validationErrors; }
public function watchFolder(KalturaDropFolder $folder) { $this->dropFolder = $folder; $this->fileTransferMgr = self::getFileTransferManager($this->dropFolder); KalturaLog::info('Watching folder [' . $this->dropFolder->id . ']'); $physicalFiles = $this->getDropFolderFilesFromPhysicalFolder(); if (count($physicalFiles) > 0) { $dropFolderFilesMap = $this->loadDropFolderFiles(); } else { $dropFolderFilesMap = array(); } $maxModificationTime = 0; foreach ($physicalFiles as &$physicalFile) { /* @var $physicalFile FileObject */ $physicalFileName = $physicalFile->filename; $utfFileName = kString::stripUtf8InvalidChars($physicalFileName); if ($physicalFileName != $utfFileName) { KalturaLog::info("File name [{$physicalFileName}] is not utf-8 compatible, Skipping file..."); continue; } if (!kXml::isXMLValidContent($utfFileName)) { KalturaLog::info("File name [{$physicalFileName}] contains invalid XML characters, Skipping file..."); continue; } if ($this->dropFolder->incremental && $physicalFile->modificationTime < $this->dropFolder->lastFileTimestamp) { KalturaLog::info("File modification time [" . $physicalFile->modificationTime . "] predates drop folder last timestamp [" . $this->dropFolder->lastFileTimestamp . "]. Skipping."); if (isset($dropFolderFilesMap[$physicalFileName])) { unset($dropFolderFilesMap[$physicalFileName]); } continue; } if ($this->validatePhysicalFile($physicalFileName)) { $maxModificationTime = $physicalFile->modificationTime > $maxModificationTime ? $physicalFile->modificationTime : $maxModificationTime; KalturaLog::info('Watch file [' . $physicalFileName . ']'); if (!array_key_exists($physicalFileName, $dropFolderFilesMap)) { try { $lastModificationTime = $physicalFile->modificationTime; $fileSize = $physicalFile->fileSize; $this->handleFileAdded($physicalFileName, $fileSize, $lastModificationTime); } catch (Exception $e) { KalturaLog::err("Error handling drop folder file [{$physicalFileName}] " . $e->getMessage()); } } else { $dropFolderFile = $dropFolderFilesMap[$physicalFileName]; //if file exist in the folder remove it from the map //all the files that are left in a map will be marked as PURGED unset($dropFolderFilesMap[$physicalFileName]); $this->handleExistingDropFolderFile($dropFolderFile); } } } foreach ($dropFolderFilesMap as $dropFolderFile) { $this->handleFilePurged($dropFolderFile->id); } if ($this->dropFolder->incremental && $maxModificationTime > $this->dropFolder->lastFileTimestamp) { $updateDropFolder = new KalturaDropFolder(); $updateDropFolder->lastFileTimestamp = $maxModificationTime; $this->dropFolderPlugin->dropFolder->update($this->dropFolder->id, $updateDropFolder); } }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { $ui_conf_id = $this->getRequestParameter("ui_conf_id"); $uiConf = uiConfPeer::retrieveByPK($ui_conf_id); if (!$uiConf) { die; } $partner_id = $uiConf->getPartnerId(); $subp_id = $uiConf->getSubpId(); $host = myPartnerUtils::getHost($partner_id); $ui_conf_swf_url = $uiConf->getSwfUrl(); if (!$ui_conf_swf_url) { $ui_conf_swf_url = "/swf/simpleeditor.swf"; } if (kString::beginsWith($ui_conf_swf_url, "http")) { $swf_url = $ui_conf_swf_url; // absolute URL } else { $use_cdn = $uiConf->getUseCdn(); $cdn_host = $use_cdn ? myPartnerUtils::getCdnHost($partner_id) : myPartnerUtils::getHost($partner_id); $swf_url = $cdn_host . myPartnerUtils::getUrlForPartner($partner_id, $subp_id) . $ui_conf_swf_url; // relative to the current host } // handle buggy case for backward compatiblity $partner_host = $host; if ($partner_host == "http://www.kaltura.com") { $partner_host = 1; } // otherwise the kse will build a flawed url with [[IMPORT]] $params = "contentUrl=" . urlencode($swf_url) . "&host=" . str_replace("http://", "", str_replace("https://", "", $partner_host)) . "&cdnHost=" . str_replace("http://", "", str_replace("https://", "", myPartnerUtils::getCdnHost($partner_id))) . "&uiConfId=" . $ui_conf_id . "&disableurlhashing=" . kConf::get('disable_url_hashing'); $wrapper_swf = myContentStorage::getFSFlashRootPath() . "/flexwrapper/" . kConf::get('editors_flex_wrapper_version') . "/FlexWrapper.swf"; $this->redirect($host . myPartnerUtils::getUrlForPartner($partner_id, $subp_id) . "{$wrapper_swf}?{$params}"); }
/** * @param SimpleXMLElement $mrss * @param SimpleXMLElement $metadata * @param kMrssParameters $mrssParams * @return SimpleXMLElement */ public function contributeMetadataObject(SimpleXMLElement $mrss, SimpleXMLElement $metadata, kMrssParameters $mrssParams = null, $currentXPath) { $currentXPath .= "/*[local-name()='" . $metadata->getName() . "']"; $metadataObject = $mrss->addChild($metadata->getName()); foreach ($metadata->attributes() as $attributeField => $attributeValue) { $metadataObject->addAttribute($attributeField, $attributeValue); } foreach ($metadata as $metadataField => $metadataValue) { if ($metadataValue instanceof SimpleXMLElement && count($metadataValue)) { $this->contributeMetadataObject($metadataObject, $metadataValue, $mrssParams, $currentXPath); } else { $metadataObject->addChild($metadataField, kString::stringToSafeXml($metadataValue)); $itemXPath = $currentXPath . "/*[local-name()='{$metadataField}']"; if ($mrssParams && is_array($mrssParams->getItemXpathsToExtend()) && in_array($itemXPath, $mrssParams->getItemXpathsToExtend())) { $relatedEntry = entryPeer::retrieveByPK((string) $metadataValue); if ($relatedEntry) { $relatedItemField = $metadataObject->addChild($metadataField . '_item'); $recursionMrssParams = null; if ($mrssParams) { $recursionMrssParams = clone $mrssParams; $recursionMrssParams->setItemXpathsToExtend(array()); // stop the recursion } $relatedEntryMrss = kMrssManager::getEntryMrssXml($relatedEntry, $relatedItemField, $recursionMrssParams); } } } } }
/** * Will forward to the uploader swf according to the ui_conf_id */ public function execute() { $ui_conf_id = $this->getRequestParameter("ui_conf_id"); $uiConf = uiConfPeer::retrieveByPK($ui_conf_id); if (!$uiConf) { KExternalErrors::dieError(KExternalErrors::UI_CONF_NOT_FOUND, "UI conf not found"); } $partner_id = $uiConf->getPartnerId(); $subp_id = $uiConf->getSubpId(); $host = requestUtils::getRequestHost(); $ui_conf_swf_url = $uiConf->getSwfUrl(); if (!$ui_conf_swf_url) { KExternalErrors::dieError(KExternalErrors::ILLEGAL_UI_CONF, "SWF URL not found in UI conf"); } if (kString::beginsWith($ui_conf_swf_url, "http")) { $swf_url = $ui_conf_swf_url; // absolute URL } else { $use_cdn = $uiConf->getUseCdn(); $cdn_host = $use_cdn ? myPartnerUtils::getCdnHost($partner_id) : myPartnerUtils::getHost($partner_id); $swf_url = $cdn_host . myPartnerUtils::getUrlForPartner($partner_id, $subp_id) . $ui_conf_swf_url; // relative to the current host } $conf_vars = $uiConf->getConfVars(); if ($conf_vars) { $conf_vars = "&" . $conf_vars; } $params = "host=" . $host . "&uiConfId=" . $ui_conf_id . $conf_vars; KExternalErrors::terminateDispatch(); $this->redirect("{$swf_url}?{$params}"); }
public function setValueFromHtmlFieldName($prefix, $html_field_name, $value) { if (kString::beginsWith($html_field_name, $prefix)) { $field_name = substr($html_field_name, strlen($prefix)); $this->setByName($field_name, $value); } }
/** * Will forward to the uploader swf according to the ui_conf_id */ public function execute() { $ui_conf_id = $this->getRequestParameter("ui_conf_id"); $uiConf = uiConfPeer::retrieveByPK($ui_conf_id); if (!$uiConf) { die; } $partner_id = $uiConf->getPartnerId(); $subp_id = $uiConf->getSubpId(); $host = requestUtils::getRequestHost(); $ui_conf_swf_url = $uiConf->getSwfUrl(); if (!$ui_conf_swf_url) { die; } if (kString::beginsWith($ui_conf_swf_url, "http")) { $swf_url = $ui_conf_swf_url; // absolute URL } else { $use_cdn = $uiConf->getUseCdn(); $cdn_host = $use_cdn ? myPartnerUtils::getCdnHost($partner_id) : myPartnerUtils::getHost($partner_id); $swf_url = $cdn_host . myPartnerUtils::getUrlForPartner($partner_id, $subp_id) . $ui_conf_swf_url; // relative to the current host } $conf_vars = $uiConf->getConfVars(); if ($conf_vars) { $conf_vars = "&" . $conf_vars; } $params = "host=" . $host . "&uiConfId=" . $ui_conf_id . $conf_vars; $this->redirect("{$swf_url}?{$params}"); }
protected function getAcl($baseUrl, array $urls) { require_once dirname(__FILE__) . '/../../../../../../infra/general/kString.class.php'; // strip the filenames of all urls foreach ($urls as &$url) { $slashPos = strrpos($url, '/'); if ($slashPos !== false) { $url = substr($url, 0, $slashPos + 1); } } $acl = kString::getCommonPrefix($urls); // the first comma in csmil denotes the beginning of the non-common URL part $commaPos = strpos($acl, ','); if ($commaPos !== false) { $acl = substr($acl, 0, $commaPos); } // if the base url has a port, remove it $parsedUrl = parse_url($baseUrl); if (isset($parsedUrl['port'])) { $baseUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host']; if (isset($parsedUrl['path'])) { $baseUrl .= $parsedUrl['path']; } } $acl = $baseUrl . $acl . '*'; return $acl; }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { $ui_conf_id = $this->getRequestParameter("ui_conf_id"); $uiConf = uiConfPeer::retrieveByPK($ui_conf_id); if (!$uiConf) { die; } $partner_id = $uiConf->getPartnerId(); $subp_id = $uiConf->getSubpId(); if (!$subp_id) { $subp_id = 0; } $host = myPartnerUtils::getHost($partner_id); $ui_conf_swf_url = $uiConf->getSwfUrl(); if (!$ui_conf_swf_url) { $ui_conf_swf_url = "/swf/ContributionWizard.swf"; } if (kString::beginsWith($ui_conf_swf_url, "http")) { $swf_url = $ui_conf_swf_url; // absolute URL } else { $use_cdn = $uiConf->getUseCdn(); $cdn_host = $use_cdn ? myPartnerUtils::getCdnHost($partner_id) : myPartnerUtils::getHost($partner_id); $swf_url = $cdn_host . myPartnerUtils::getUrlForPartner($partner_id, $subp_id) . $ui_conf_swf_url; // relative to the current host } $params = "contentUrl=" . urlencode($swf_url) . "&host=" . str_replace("http://", "", str_replace("https://", "", $host)) . "&cdnHost=" . str_replace("http://", "", str_replace("https://", "", myPartnerUtils::getCdnHost($partner_id))) . "&uiConfId=" . $ui_conf_id; $wrapper_swf = myContentStorage::getFSFlashRootPath() . "/flexwrapper/" . kConf::get('kcw_flex_wrapper_version') . "/FlexWrapper.swf"; $this->redirect($host . myPartnerUtils::getUrlForPartner($partner_id, $subp_id) . "{$wrapper_swf}?{$params}"); }
public function tokenToKey($matches) { $token = $matches[0]; $key = "@K" . kString::generateStringId() . "K@"; $this->tokensMap[$key] = $token; return $key; }
/** * Executes addComment action, which returns a form enabling the insertion of a comment * The request may include 1 fields: entry id. */ protected function executeImpl(kshow $kshow, entry &$entry) { $version = @$_REQUEST["version"]; // it's a path on the disk if (kString::beginsWith($version, ".")) { // someone is trying to hack in the system return sfView::ERROR; } // in case we're making a roughcut out of a regular invite, we start from scratch if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW || $entry->getDataPath($version) === null) { $this->xml_content = "<xml></xml>"; return; } // fetch content of file from disk - it should hold the XML $file_name = myContentStorage::getFSContentRootPath() . "/" . $entry->getDataPath($version); //echo "[$file_name]"; if (kString::endsWith($file_name, "xml")) { if (file_exists($file_name)) { $this->xml_content = kFile::getFileContent($file_name); // echo "[" . $this->xml_content . "]" ; } else { $this->xml_content = "<xml></xml>"; } myMetadataUtils::updateEntryForPending($entry, $version, $this->xml_content); } else { return sfView::ERROR; } // this is NOT an xml file we are looking for ! }
/** * @param FileSync $fileSync * @return string */ protected function doGetFileSyncUrl(FileSync $fileSync) { $url = parent::doGetFileSyncUrl($fileSync); if (in_array($fileSync->getPartnerId(), array(666132, 628012, 357521, 560751)) && kString::beginsWith($url, "mp4:")) { $url .= ".mp4"; } return $url; }
public function toObject($dbObject = null, $skip = array()) { /** @var kObjectTask $dbObject */ $dbObject = parent::toObject($dbObject, $skip); $flavorParamsIds = array_unique(kString::fromCommaSeparatedToArray($this->flavorParamsIds)); $dbObject->setDataValue('flavorParamsIds', $flavorParamsIds); $dbObject->setDataValue('reconvert', $this->reconvert); return $dbObject; }
protected function removeFiles($namePrefix) { $namePrefix = $this->normalizeSlashes($namePrefix); foreach ($this->_files as $name => $data) { if (kString::beginsWith($name, $namePrefix)) { unset($this->_files[$name]); } } }
protected function writeFullXmlNode($nodeName, $value, $level, $attributes = array()) { $res = ''; $res .= $this->writeOpenXmlNode($nodeName, $level, $attributes, false); $res .= kString::xmlEncode(kString::xmlDecode("{$value}")); //to create a valid XML (without unescaped special chars) //we decode before encoding to avoid breaking an xml which its special chars had already been escaped $res .= $this->writeClosingXmlNode($nodeName, 0); return $res; }
/** Returns newly created puser - after creating it's corresponding kuser. If the puser_kuser already exists && $verify_not_exists==true , don't create a new one and return the existing one */ public static function createPuserKuser($partner_id, $subp_id, $puser_id, $kuser_name, $puser_name, $create_kuser = false, $kuser = null) { $puser_kuser = self::retrieveByPartnerAndUid($partner_id, $subp_id, $puser_id, true); if (!$kuser) { $kuser = kuserPeer::getKuserByPartnerAndUid($partner_id, $puser_id, true); // don't create an existing kuser! } if ($puser_kuser) { if (!$create_kuser) { // if the puser_kuser already exists - don't re-create it $puser_kuser->exists = true; return $puser_kuser; } else { // puser_kuser exists but it's OK // this might be the case where we don't mind creating a new one each time } } else { $puser_kuser = new PuserKuser(); } $c = new Criteria(); $c->add(self::PARTNER_ID, $partner_id); $c->add(self::PUSER_ID, $puser_id); $partner_puser_kuser = self::doSelectOne($c); if ($kuser !== null) { $kuser_id = $kuser->getId(); } else { if ($partner_puser_kuser) { $kuser_id = $partner_puser_kuser->getKuserId(); $kuser = kuserPeer::retrieveByPK($kuser_id); } else { // create kuser for this puser $kuser = new kuser(); $kuser->setScreenName($kuser_name); list($firstName, $lastName) = kString::nameSplit($kuser_name); $kuser->setFirstName($firstName); $kuser->setLastName($lastName); $kuser->setPartnerId($partner_id); // set puserId for forward compatibility with PS3 $kuser->setPuserId($puser_id); $kuser->setStatus(KuserStatus::ACTIVE); // so he won't appear in the search $kuser->save(); $kuser_id = $kuser->getId(); } } $puser_kuser->setPartnerId($partner_id); $puser_kuser->setSubpId($subp_id); $puser_kuser->setPuserId($puser_id); $puser_kuser->setKuserId($kuser_id); $puser_kuser->setPuserName($puser_name); $puser_kuser->save(); $puser_kuser->setkuser($kuser); return $puser_kuser; }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { $uiconf_id = $this->getRequestParameter('uiconf_id'); if (!$uiconf_id) { KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'uiconf_id'); } $uiConf = uiConfPeer::retrieveByPK($uiconf_id); if (!$uiConf) { KExternalErrors::dieError(KExternalErrors::UI_CONF_NOT_FOUND); } $partner_id = $this->getRequestParameter('partner_id', $uiConf->getPartnerId()); if (!$partner_id) { KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'partner_id'); } $partner_host = myPartnerUtils::getHost($partner_id); $partner_cdnHost = myPartnerUtils::getCdnHost($partner_id); $use_cdn = $uiConf->getUseCdn(); $host = $use_cdn ? $partner_cdnHost : $partner_host; $ui_conf_html5_url = $uiConf->getHtml5Url(); if (kConf::hasMap("optimized_playback")) { $optimizedPlayback = kConf::getMap("optimized_playback"); if (array_key_exists($partner_id, $optimizedPlayback)) { // force a specific kdp for the partner $params = $optimizedPlayback[$partner_id]; if (array_key_exists('html5_url', $params)) { $ui_conf_html5_url = $params['html5_url']; } } } if (kString::beginsWith($ui_conf_html5_url, "http")) { $url = $ui_conf_html5_url; // absolute URL } else { if ($ui_conf_html5_url) { $url = $host . $ui_conf_html5_url; } else { $html5_version = kConf::get('html5_version'); $url = "{$host}/html5/html5lib/{$html5_version}/mwEmbedLoader.php"; } } // append uiconf_id and partner id for optimizing loading of html5 library. append them only for "standard" urls by looking for the mwEmbedLoader.php suffix if (kString::endsWith($url, "mwEmbedLoader.php")) { $url .= "/p/{$partner_id}/uiconf_id/{$uiconf_id}"; $entry_id = $this->getRequestParameter('entry_id'); if ($entry_id) { $url .= "/entry_id/{$entry_id}"; } } requestUtils::sendCachingHeaders(60); header("Pragma:"); kFile::cacheRedirect($url); header("Location:{$url}"); die; }
private static function calculateId() { $dc = kDataCenterMgr::getCurrentDc(); for ($i = 0; $i < 10; ++$i) { $id = $dc["id"] . '_' . kString::generateStringId(); $existing_object = entryPeer::retrieveByPk($id); if (!$existing_object) { return $id; } } die; }
public static function rebuildUsersListXml($users) { //"<contributor uid='$puser_id' name='$name' pic='$pic' sex='$sex'/>"; $data = ""; foreach ($users as $user) { $puser_id = $user['uid']; $name = $user['name']; $pic = $user['pic']; $sex = $user['sex']; $data .= "<contributor uid='{$puser_id}' name='" . kString::xmlEncode($name) . "' pic='{$pic}' sex='{$sex}'/>"; } return $data; }
/** * generate unique string id for annotation */ public function getUniqueAnnotationId() { $dc = kDataCenterMgr::getCurrentDc(); for ($i = 0; $i < 10; $i++) { $id = $dc["id"] . '_' . kString::generateStringId(); $existingObject = AnnotationPeer::retrieveByPK($id); if ($existingObject) { KalturaLog::log(__METHOD__ . ": id [{$id}] already exists"); } else { return $id; } } throw new Exception("Could not find unique id for annotation"); }
/** * generate unique string id for CuePoint */ private function calculateId() { $currentDcId = kDataCenterMgr::getCurrentDcId(); for ($i = 0; $i < 10; $i++) { $id = $currentDcId . '_' . kString::generateStringId(); $existingObject = CuePointPeer::retrieveByPKNoFilter($id); if ($existingObject) { KalturaLog::log(__METHOD__ . ": id [{$id}] already exists"); } else { return $id; } } throw new Exception("Could not find unique id for CuePoint"); }
private function calculateId() { $dc = kDataCenterMgr::getCurrentDc(); for ($i = 0; $i < 10; $i++) { $id = $dc["id"] . '_' . kString::generateStringId(); $existingObject = AppTokenPeer::retrieveByPkNoFilter($id); if ($existingObject) { KalturaLog::log("ID [{$id}] already exists"); } else { return $id; } } throw new Exception("Could not find unique id for AppToken"); }
/** * @param SimpleXMLElement $mrss * @param SimpleXMLElement $metadata * @param kMrssParameters $mrssParams * @return SimpleXMLElement */ public function contributeMetadataObject(SimpleXMLElement $mrss, SimpleXMLElement $metadata, kMrssParameters $mrssParams = null, $currentXPath) { $currentXPath .= "/*[local-name()='" . $metadata->getName() . "']"; $metadataObject = $mrss->addChild($metadata->getName()); foreach ($metadata->attributes() as $attributeField => $attributeValue) { $metadataObject->addAttribute($attributeField, $attributeValue); } foreach ($metadata as $metadataField => $metadataValue) { if ($metadataValue instanceof SimpleXMLElement && count($metadataValue)) { $this->contributeMetadataObject($metadataObject, $metadataValue, $mrssParams, $currentXPath); } else { $metadataObject->addChild($metadataField, kString::stringToSafeXml($metadataValue)); } } }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { defPartnerservices2baseAction::disableCache(); $email = trim($this->getPM("adminKuser_email")); $new_email = trim($this->getP("new_email")); $old_password = trim($this->getPM("adminKuser_password", null)); $password = trim($this->getPM("new_password", null)); if ($new_email) { if (!kString::isEmailString($new_email)) { $f_name = "new_email"; $this->addException(APIErrors::INVALID_FIELD_VALUE, $f_name); } } try { UserLoginDataPeer::updateLoginData($email, $old_password, $new_email, $password); } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::LOGIN_DATA_NOT_FOUND) { $this->addException(APIErrors::ADMIN_KUSER_NOT_FOUND); return null; } if ($code == kUserException::WRONG_PASSWORD) { $this->addException(APIErrors::ADMIN_KUSER_WRONG_OLD_PASSWORD); return null; } if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) { $this->addException(APIErrors::PASSWORD_STRUCTURE_INVALID); return null; } if ($code == kUserException::PASSWORD_ALREADY_USED) { $this->addException(APIErrors::PASSWORD_ALREADY_USED); return null; } if ($code == kUserException::INVALID_EMAIL) { $this->addException(APIErrors::INVALID_FIELD_VALUE, 'new_email'); return null; } if ($code == kUserException::LOGIN_ID_ALREADY_USED) { $this->addException(APIErrors::LOGIN_ID_ALREADY_USED); return null; } throw $e; } if ($new_email) { $this->addMsg("new_email", $new_email); } $this->addMsg("new_password", $password); }
/** * @return int unique id per request */ public function getUniqueRequestId() { if (!is_null(self::$uniqueRequestId)) { return self::$uniqueRequestId; } $dcId = kDataCenterMgr::getCurrentDcId(); for ($i = 0; $i < 10; ++$i) { $requestId = $dcId . '_' . kString::generateStringId(); $exists = AuditTrailPeer::retrieveByRequestId($requestId); if (!$exists) { self::$uniqueRequestId = $requestId; return self::$uniqueRequestId; } } throw new kAuditTrailException('Unable to generate unique id', kAuditTrailException::UNIQUE_ID_NOT_GENERATED); }
/** * Update admin user password and email * * @param string $email * @param string $password * @param string $newEmail Optional, provide only when you want to update the email * @param string $newPassword * * @throws KalturaErrors::INVALID_FIELD_VALUE * @throws KalturaErrors::LOGIN_DATA_NOT_FOUND * @throws KalturaErrors::WRONG_OLD_PASSWORD * @throws KalturaErrors::PASSWORD_STRUCTURE_INVALID * @throws KalturaErrors::PASSWORD_ALREADY_USED * @throws KalturaErrors::LOGIN_ID_ALREADY_USED */ protected function updateLoginDataImpl($email, $password, $newEmail = "", $newPassword = "", $newFirstName, $newLastName) { KalturaResponseCacher::disableCache(); $this->validateApiAccessControlByEmail($email); if ($newEmail != "") { if (!kString::isEmailString($newEmail)) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, "newEmail"); } } try { UserLoginDataPeer::updateLoginData($email, $password, $newEmail, $newPassword, $newFirstName, $newLastName); } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::LOGIN_DATA_NOT_FOUND) { throw new KalturaAPIException(KalturaErrors::LOGIN_DATA_NOT_FOUND); } else { if ($code == kUserException::WRONG_PASSWORD) { if ($password == $newPassword) { throw new KalturaAPIException(KalturaErrors::USER_WRONG_PASSWORD); } else { throw new KalturaAPIException(KalturaErrors::WRONG_OLD_PASSWORD); } } else { if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) { $c = new Criteria(); $c->add(UserLoginDataPeer::LOGIN_EMAIL, $email); $loginData = UserLoginDataPeer::doSelectOne($c); $invalidPasswordStructureMessage = $loginData->getInvalidPasswordStructureMessage(); throw new KalturaAPIException(KalturaErrors::PASSWORD_STRUCTURE_INVALID, $invalidPasswordStructureMessage); } else { if ($code == kUserException::PASSWORD_ALREADY_USED) { throw new KalturaAPIException(KalturaErrors::PASSWORD_ALREADY_USED); } else { if ($code == kUserException::INVALID_EMAIL) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'email'); } else { if ($code == kUserException::LOGIN_ID_ALREADY_USED) { throw new KalturaAPIException(KalturaErrors::LOGIN_ID_ALREADY_USED); } } } } } } throw $e; } }
protected function getAcl($baseUrl, array $urls) { require_once dirname(__FILE__) . '/../../../../../../infra/general/kString.class.php'; // strip the filenames of all urls foreach ($urls as &$url) { $slashPos = strrpos($url, '/'); if ($slashPos !== false) { $url = substr($url, 0, $slashPos + 1); } } $acl = kString::getCommonPrefix($urls); // the first comma in csmil denotes the beginning of the non-common URL part $commaPos = strpos($acl, ','); if ($commaPos !== false) { $acl = substr($acl, 0, $commaPos); } $acl = $baseUrl . $acl . '*'; return $acl; }
/** * Update admin user password and email * * @param string $email * @param string $password * @param string $newEmail Optional, provide only when you want to update the email * @param string $newPassword * * @throws KalturaErrors::INVALID_FIELD_VALUE * @throws KalturaErrors::LOGIN_DATA_NOT_FOUND * @throws KalturaErrors::WRONG_OLD_PASSWORD * @throws KalturaErrors::PASSWORD_STRUCTURE_INVALID * @throws KalturaErrors::PASSWORD_ALREADY_USED * @throws KalturaErrors::INVALID_FIELD_VALUE * @throws KalturaErrors::LOGIN_ID_ALREADY_USED */ protected function updateLoginDataImpl($email, $password, $newEmail = "", $newPassword = "", $newFirstName, $newLastName) { KalturaResponseCacher::disableCache(); if ($newEmail != "") { if (!kString::isEmailString($newEmail)) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, "newEmail"); } } try { UserLoginDataPeer::updateLoginData($email, $password, $newEmail, $newPassword, $newFirstName, $newLastName); } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::LOGIN_DATA_NOT_FOUND) { throw new KalturaAPIException(KalturaErrors::LOGIN_DATA_NOT_FOUND); } else { if ($code == kUserException::WRONG_PASSWORD) { if ($password == $newPassword) { throw new KalturaAPIException(KalturaErrors::USER_WRONG_PASSWORD); } else { throw new KalturaAPIException(KalturaErrors::WRONG_OLD_PASSWORD); } } else { if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) { throw new KalturaAPIException(KalturaErrors::PASSWORD_STRUCTURE_INVALID); } else { if ($code == kUserException::PASSWORD_ALREADY_USED) { throw new KalturaAPIException(KalturaErrors::PASSWORD_ALREADY_USED); } else { if ($code == kUserException::INVALID_EMAIL) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'email'); } else { if ($code == kUserException::LOGIN_ID_ALREADY_USED) { throw new KalturaAPIException(KalturaErrors::LOGIN_ID_ALREADY_USED); } } } } } } throw $e; } }
/** * Enter description here... * * @param BaseObject $obj - the object to be invoked with method $date_method_str * @param unknown_type $format * @return formated date according to kaltura's string rules */ public static function formatKalturaDate(BaseObject $obj, $date_method_str, $format = self::KALTURA_FORMAT) { // prepare an array with the object to invoke & the date_method $f = array($obj, $date_method_str); if ($format == self::KALTURA_FORMAT) { // call parent with NULL so there will be no formating of the original date $params = array(NULL); $date = call_user_func_array($f, $params); // now - we'll format it our way return kString::formatDate($date); } else { if ($format == self::MODEL_DEFAULT_FORMAT) { // get default value from obj and pass no values return call_user_func($f); } else { // get the value from obj and use the given format return call_user_func($f, $format); } } }