protected function calculateId() { $allChars = '0123456789abcdefghijklmnopqrstuvwxyz'; $dcChars = str_split($allChars, strlen($allChars) / count(kDataCenterMgr::getAllDcs())); $dc = kDataCenterMgr::getCurrentDc(); $dcId = (int) $dc["id"]; $currentDcChars = $dcChars[$dcId]; for ($i = 0; $i < 10; $i++) { $dcChar = substr($currentDcChars, rand(0, strlen($currentDcChars) - 1), 1); if (!$dcChar) { $dcChar = '0'; } $id = $dcChar . kString::generateStringId(3); $existingObject = ShortLinkPeer::retrieveByPK($id); if ($existingObject) { KalturaLog::log("id [{$id}] already exists"); } else { return $id; } } throw new Exception("Could not find unique id for short link"); }
/** * Serves short link * * @action goto * @param string $id * @param bool $proxy proxy the response instead of redirect * @return file * * @throws KalturaErrors::INVALID_OBJECT_ID */ function gotoAction($id, $proxy = false) { KalturaResponseCacher::disableCache(); $dbShortLink = ShortLinkPeer::retrieveByPK($id); if (!$dbShortLink) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id); } if ($proxy) { kFile::dumpUrl($dbShortLink->getFullUrl(), true, true); } header('Location: ' . $dbShortLink->getFullUrl()); die; }