public function execute() { $this->forceSystemAuthentication(); $partner_id = $this->getRequestParameter('partner_id', -1); if ($partner_id >= 0) { myPartnerUtils::applyPartnerFilters($partner_id); } $this->partner_id = $partner_id; $order = $this->getRequestParameter('sort', kshow::KSHOW_SORT_MOST_VIEWED); $page = $this->getRequestParameter('page', 1); //$this->producer_id = $this->getRequestParameter('producer_id', 0 ); //$this->kaltura_part_of_flag = $this->getRequestParameter('partof', 0 ); $pager = kshowPeer::getOrderedPager($order, 10, $page); $kshow_list = $pager->getResults(); dashboardUtils::updateKshowsRoughcutCount($kshow_list); $kshowsData = array(); foreach ($kshow_list as $kshow) { $kshowsData[] = $this->createKShowData($kshow, $order); } // following variables will be used by the view $this->firstTime = $this->getRequestParameter('first', 1) == 1; $this->order = $order; $this->page = $page; $this->lastPage = $pager->getLastPage(); $this->numResults = $pager->getNbResults(); $this->kshowsData = $kshowsData; // allow the action buttons to show only for shows the user produced, and only for authenticated users, on their own pages $this->allowactions = true; // !$this->kaltura_part_of_flag && $this->getUser()->isAuthenticated() && $this->getUser()->getAttribute('id') == $this->producer_id; }
public function execute() { $this->forceSystemAuthentication(); $partner_id = $this->getRequestParameter('partner_id', -1); if ($partner_id >= 0) { myPartnerUtils::applyPartnerFilters($partner_id); } $this->partner_id = $partner_id; $order = $this->getRequestParameter('sort', kuser::KUSER_SORT_MOST_VIEWED); $page = $this->getRequestParameter('page', 1); $pager = kuserPeer::getAllUsersOrderedPager($order, 10, $page); $kuser_list = $pager->getResults(); dashboardUtils::updateKusersRoughcutCount($kuser_list); $kusersData = array(); foreach ($kuser_list as $kuser) { $kusersData[] = $this->createkuserData($kuser, $order); } // following variables will be used by the view $this->firstTime = $this->getRequestParameter('first', 1) == 1; $this->order = $order; $this->page = $page; $this->lastPage = $pager->getLastPage(); $this->numResults = $pager->getNbResults(); $this->kusersData = $kusersData; // allow the action buttons to show only for entires the user on their own pages $this->allowactions = true; }
/** * Gives a system applicative snapsot */ public function execute() { myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL3; $this->forceSystemAuthentication(); $partner_id = $this->getRequestParameter('partner_id', -1); if ($partner_id >= 0) { myPartnerUtils::applyPartnerFilters($partner_id); } $this->partner_id = $partner_id; $limit = $this->getRequestParameter('limit', '30'); if ($limit > 300) { $limit = 300; } $bands_only = $this->getRequestParameter("bands", false) != null; $modified_only = $this->getRequestParameter("modified", false) != null; $this->bands_only = $bands_only; $this->modified_only = $modified_only; $this->kshows_with_new_entries = $modified_only ? dashboardUtils::getUpdatedKshows() : null; $yesterday = mktime(0, 0, 0, date("m"), date("d") - 1, date("Y")); $lastweek = mktime(0, 0, 0, date("m"), date("d") - 7, date("Y")); $query_esterday = date('Y-m-d', $yesterday); $query_lastweek = date('Y-m-d', $lastweek); $modified_band_ids = $modified_only ? array_keys($this->kshows_with_new_entries) : null; if ($modified_only) { // TODO - this chunk was copied from the code bellow with minor changes - generalize ! $c = new Criteria(); // $c->add ( kshowPeer::ID , $modified_band_ids , Criteria::IN ); // search only the given IDs $this->bandsOnly($bands_only, $modified_band_ids, $c, kshowPeer::PARTNER_ID); $this->kshow_count = kshowPeer::doCount($c); $criterion = $c->getNewCriterion(kshowPeer::CREATED_AT, $query_esterday, Criteria::GREATER_EQUAL); $c->add($criterion); $this->kshow_count1 = kshowPeer::doCount($c); $criterion = $c->getNewCriterion(kshowPeer::CREATED_AT, $query_lastweek, Criteria::GREATER_EQUAL); $c->add($criterion); $this->kshow_count7 = kshowPeer::doCount($c); $c->setLimit($limit); //$c->hints = array(kshowPeer::TABLE_NAME => "created_at_index"); $c->addDescendingOrderByColumn(kshowPeer::CREATED_AT); $c->remove(kshowPeer::CREATED_AT); $c->addJoin(kshowPeer::PRODUCER_ID, kuserPeer::ID, Criteria::LEFT_JOIN); $this->kshows = kshowPeer::doSelectJoinkuser($c); $this->bands_only = $bands_only; $this->entry_count = 0; $this->entry_count1 = 0; $this->entry_count7 = 0; $this->entries = array(); $this->kuser_count = 0; $this->kuser_count1 = 0; $this->kuser_count7 = 0; $this->kusers = array(); dashboardUtils::updateKshowsRoughcutCount($this->kshows); return sfView::SUCCESS; } $c = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $c, kshowPeer::PARTNER_ID); $this->kshow_count = kshowPeer::doCount($c); $d = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $d, kshowPeer::PARTNER_ID); $criterion = $c->getNewCriterion(kshowPeer::CREATED_AT, $query_esterday, Criteria::GREATER_EQUAL); $d->add($criterion); $this->kshow_count1 = kshowPeer::doCount($d); $e = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $e, kshowPeer::PARTNER_ID); $criterion = $c->getNewCriterion(kshowPeer::CREATED_AT, $query_lastweek, Criteria::GREATER_EQUAL); $e->add($criterion); $this->kshow_count7 = kshowPeer::doCount($e); //$this->kshow_count = kshowPeer::doCount( $c ); $c->setLimit($limit); //$c->hints = array(kshowPeer::TABLE_NAME => "created_at_index"); $c->addDescendingOrderByColumn(kshowPeer::CREATED_AT); $c->addJoin(kshowPeer::PRODUCER_ID, kuserPeer::ID, Criteria::LEFT_JOIN); $this->kshows = kshowPeer::doSelectJoinkuser($c); $c = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $c, entryPeer::PARTNER_ID); $this->entry_count = entryPeer::doCount($c); $d = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $d, entryPeer::PARTNER_ID); $criterion = $c->getNewCriterion(entryPeer::CREATED_AT, $query_esterday, Criteria::GREATER_EQUAL); $d->add($criterion); $this->entry_count1 = entryPeer::doCount($d); $e = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $e, entryPeer::PARTNER_ID); $criterion = $c->getNewCriterion(entryPeer::CREATED_AT, $query_lastweek, Criteria::GREATER_EQUAL); $e->add($criterion); $this->entry_count7 = entryPeer::doCount($e); $c->setLimit($limit); //$c->hints = array(entryPeer::TABLE_NAME => "created_at_index"); $c->addDescendingOrderByColumn(entryPeer::CREATED_AT); $c->add(entryPeer::TYPE, entryType::MEDIA_CLIP); // we don't want entries that // $c->addJoin(entryPeer::KUSER_ID, kuserPeer::ID, Criteria::INNER_JOIN); // $c->addJoin(entryPeer::KSHOW_ID, kshowPeer::ID, Criteria::INNER_JOIN); $this->entries = entryPeer::doSelectJoinAll($c); $c = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $c, kuserPeer::PARTNER_ID); $d = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $d, kuserPeer::PARTNER_ID); $criterion = $c->getNewCriterion(kuserPeer::CREATED_AT, $query_esterday, Criteria::GREATER_EQUAL); $d->add($criterion); $this->kuser_count1 = kuserPeer::doCount($d); $e = new Criteria(); $this->bandsOnly($bands_only, $modified_band_ids, $e, kuserPeer::PARTNER_ID); $criterion = $c->getNewCriterion(kuserPeer::CREATED_AT, $query_lastweek, Criteria::GREATER_EQUAL); $e->add($criterion); $this->kuser_count7 = kuserPeer::doCount($e); $this->kuser_count = kuserPeer::doCount($c); $c->setLimit($limit); $c->addDescendingOrderByColumn(kuserPeer::CREATED_AT); $this->kusers = kuserPeer::doSelect($c); dashboardUtils::updateKusersRoughcutCount($this->kusers); dashboardUtils::updateKshowsRoughcutCount($this->kshows); return sfView::SUCCESS; }
public function initService($serviceId, $serviceName, $actionName) { // init service and action name $this->serviceId = $serviceId; $this->serviceName = $serviceName; $this->actionName = $actionName; // impersonated partner = partner parameter from the request $this->impersonatedPartnerId = kCurrentContext::$partner_id; $this->ks = kCurrentContext::$ks_object ? kCurrentContext::$ks_object : null; // operating partner = partner from the request or the ks partner $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; // if there is no session, assume it's partner 0 using actions that doesn't require ks if (is_null($partnerId)) { $partnerId = 0; } $this->partner = PartnerPeer::retrieveByPK($partnerId); if (!$this->partner) { $this->partner = null; } // check if current aciton is allowed and if private partner data access is allowed $allowPrivatePartnerData = false; $actionPermitted = $this->isPermitted($allowPrivatePartnerData); // action not permitted at all, not even kaltura network if (!$actionPermitted) { $e = new KalturaAPIException(APIErrors::SERVICE_FORBIDDEN, $this->serviceId . '->' . $this->actionName); //TODO: should sometimes thorow MISSING_KS instead header("X-Kaltura:error-" . $e->getCode()); header("X-Kaltura-App: exiting on error " . $e->getCode() . " - " . $e->getMessage()); throw $e; } // init partner filter parameters $this->private_partner_data = $allowPrivatePartnerData; $this->partnerGroup = kPermissionManager::getPartnerGroup($this->serviceId, $this->actionName); if ($this->globalPartnerAllowed($this->actionName)) { $this->partnerGroup = PartnerPeer::GLOBAL_PARTNER . ',' . trim($this->partnerGroup, ','); } // apply partner filters according to current context and permissions myPartnerUtils::resetAllFilters(); myPartnerUtils::applyPartnerFilters($partnerId, $this->private_partner_data, $this->partnerGroup, $this->kalturaNetworkAllowed($this->actionName)); }
public function execute($add_extra_debug_data = true) { date_default_timezone_set(kConf::get("date_default_timezone")); // TODO - remove for production - use some configuration to determine kConfigTable::$should_use_cache = false; $start_impl = $end_impl = 0; $nocache = false; if ($this->getP("nocache")) { $nocache = true; $this->logMessage("Not using cache!"); objectWrapperBase::useCache(false); } $add_benchmarks = $this->getP("add_benchmarks", false); // while testing our system - will match each service agains its description // $this->matchInDescription(); $this->msg = array(); $this->error = array(); $this->debug = array(); $start_time = microtime(true); $start = microtime(true); $this->benchmarkStart("beforeImpl"); $this->response_type = $this->getP("format", self::DEFAULT_FORMAT); // /* $should_debug = $this->getP ( "should_debug" , true ); if ( $should_debug == "false" ) $this->should_debug = false; */ if ($this->should_debug && $add_extra_debug_data) { $this->benchmarkStart("signature"); $sig_type = $this->getP("sigtype", self::SIG_TYPE_POST); $signature_params = self::getParamsFromSigType($sig_type); $signatura_valid = self::validateSignature($signature_params); $this->benchmarkEnd("signature"); $this->addDebug("sigtype", $sig_type); $this->addDebug("validateSignature", $signatura_valid); $this->addDebug("signature", self::signature($signature_params)); // $this->addDebug( "rawsignature" , self::signature( $signature_params , false ) ); } $partner_id = $this->getP("partner_id"); if (!$partner_id) { $partner_id = $this->getP("partnerId"); } $subp_id = $this->getP("subp_id"); if (!$subp_id) { $subp_id = $this->getP("subpId"); } $puser_id = $this->getP("uid"); $ks_str = $this->getP("ks"); if ($ks_str == "{ks}") { $ks_str = ""; } // if the client DIDN'T replace the dynamic ks - ignore it // the $execution_cache_key can be used by services to cache the results depending on the inpu parameters // if the $execution_cache_key is not null, the rendere will search for the result of the rendering depending on the $execution_cache_key // if it doesn't find it - it will create it (per format) and store it for next time $execution_cache_key = null; // moved the renderer here to see if has the $execution_cache_key and if so - skip the implementation $renderer = new kalturaWebserviceRenderer($this->response_context); $private_partner_data = false; try { try { $arr = list($partner_id, $subp_id, $uid, $private_partner_data) = $this->validateTicketSetPartner($partner_id, $subp_id, $puser_id, $ks_str); } catch (Exception $ex) { KalturaLog::log('validateTicketSetPartner failed - not caching response'); defPartnerservices2baseAction::disableCache(); throw $ex; } // if PS2 permission validation is enabled for the current partner, only the actions defined in kConf's parameter "ps2_actions_not_blocked_by_permissions" will be allowed $currentPartner = $this->getPartner(); if ($currentPartner && $currentPartner->getEnabledService(PermissionName::FEATURE_PS2_PERMISSIONS_VALIDATION)) { if (!in_array(strtolower(get_class($this)), kConf::get('ps2_actions_not_blocked_by_permissions'))) { KalturaLog::log('PS2 action ' . get_class($this) . ' is being blocked for partner ' . $currentPartner->getId() . ' defined with FEATURE_PS2_PERMISSIONS_VALIDATION enabled'); $this->addException(APIErrors::SERVICE_FORBIDDEN, get_class($this)); } } $this->private_partner_data = $private_partner_data; //print_r ( $arr ); // TODO - validate the matchIp is ok with the user's IP $this->validateIp(); // most services should not attempt to cache the results - for them this will return null $execution_cache_key = $this->getExecutionCacheKeyWrapper($partner_id, $subp_id, $puser_id); // if the key is not null - it will be used in the renderer for using the cotent from the cache if ($nocache) { $renderer->deleteCacheKey($execution_cache_key, $this->response_type); } else { $renderer->setCacheKey($execution_cache_key); } if (!$renderer->hasContentForCacheKey($this->response_type)) { $this->benchmarkStart("applyPartnerFilters"); //init entitlement before set the default criteire by myPartnerUtils::applyPartnerFilters kEntitlementUtils::initEntitlementEnforcement(); // apply filters for Criteria so there will be no chance of exposure of date from other partners ! // TODO - add the parameter for allowing kaltura network myPartnerUtils::applyPartnerFilters($partner_id, $private_partner_data, $this->partnerGroup2(), $this->kalturaNetwork2()); $this->benchmarkEnd("applyPartnerFilters"); $this->benchmarkStart("puserKuser"); list($partner_id, $subp_id, $puser_id, $partner_prefix) = $this->preparePartnerPuserDetails($partner_id, $subp_id, $puser_id); $puser_kuser = $this->getPuserKuser($partner_id, $subp_id, $puser_id); $this->benchmarkEnd("puserKuser"); $this->benchmarkEnd("beforeImpl"); // ----------------------------- impl -------------------------- $start_impl = microtime(true); $result = $this->executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser); $end_impl = microtime(true); kEventsManager::flushEvents(); } else { /// the renderer claims to have the desired result ! just flow down the code ... ;) } // ----------------------------- impl -------------------------- } catch (APIException $api_ex) { $message = $api_ex->getMessage(); if ($this->should_debug && $message) { $this->addError(APIErrors::SERVERL_ERROR, "[{$message}]"); } elseif ($api_ex->api_code) { call_user_func_array(array(&$this, 'addError'), $api_ex->extra_data); // $this->addError ( $api_ex->api_code ,$api_ex->extra_data ); } } catch (PropelException $pex) { KalturaLog::alert($pex->getMessage()); $this->addError(APIErrors::INTERNAL_DATABASE_ERROR); } catch (Exception $ex) { $this->addError(APIErrors::INTERNAL_SERVERL_ERROR, $ex->getMessage()); KalturaLog::err($ex->getMessage()); } $execute_impl_end_time = microtime(true); // render according to the format_type $res = array(); $this->addMsg("serverTime", time()); $res['result'] = $this->msg; $res['error'] = $this->error; if ($this->should_debug) { // this specific debug line should be used $this->addDebug("execute_impl_time", $end_impl - $start_impl); $this->addDebug("execute_time", $execute_impl_end_time - $start_time); // will be used as a place holder and will be replaced after the rendering. if ($add_extra_debug_data) { $this->addDebug("total_time", self::__TOTAL_TIME__); } if ($add_benchmarks && count($this->benchmarks) > 0) { $this->addDebug("host", @$_ENV["HOSTNAME"]); $this->addDebug("benchmarks", $this->getBenchmarks()); } $res['debug'] = $this->debug; } // ignore all the errors and debug - the first msg is the only html used if ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_HTML) { $res = "<html>"; foreach ($this->msg as $html_bit) { $res .= $html_bit; } $res .= "</html>"; } if ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_MRSS) { // in case of mRss - render only the result not the errors ot the debug list($response, $content_type) = $renderer->renderDataInRequestedFormat($res['result'], $this->response_type, true, self::$escape_text); } else { list($response, $content_type) = $renderer->renderDataInRequestedFormat($res, $this->response_type, true, self::$escape_text); } $end_time = microtime(true); if (is_string($response)) { $this->logMessage("Rendereing took: [" . ($end_time - $start_time) . "] seconds. Response size [" . strlen($response) . "]", SF_LOG_WARNING); $this->logMessage($response, SF_LOG_WARNING); } else { $this->logMessage("Rendereing took: [" . ($end_time - $start_time) . "]"); } if ($this->should_debug && $add_extra_debug_data) { // fix the total time including the render time $str_time = (string) ($end_time - $start_time); if ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP) { // replcate the placehoder with the real execution time // this is a nasty hack - we replace the serialized PHP value - the length of the placeholder is 14 characters // the length of the str_time can be less - replace the whole string phrase $replace_string = 's:' . strlen($str_time) . ':"' . $str_time; $response = str_replace('s:14:"' . self::__TOTAL_TIME__, $replace_string, $response); } elseif ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP_ARRAY || $this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP_OBJECT) { // the $response is not a string - we can't just replace it $res["debug"]["total_time"] = $str_time; } elseif ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_MRSS) { // do nothing to the result } else { $response = str_replace(self::__TOTAL_TIME__, $str_time, $response); } } header("Access-Control-Allow-Origin:*"); // avoid html5 xss issues $this->setContentType($content_type); // while testing our system - will match each service agains its description // $this->matchOutDescription(); return $response; }
/** * apply partner filters according to current context and permissions * * @param int $partnerId */ protected function setPartnerFilters($partnerId) { myPartnerUtils::resetAllFilters(); myPartnerUtils::applyPartnerFilters($partnerId, $this->private_partner_data, $this->partnerGroup(), $this->kalturaNetworkAllowed($this->actionName)); }
/** * Function creates new partner, saves all the required data to it, and copies objects & filesyncs of template content to its ID. * @param string $partner_name * @param string $contact * @param string $email * @param CommercialUseType $ID_is_for * @param string $SDK_terms_agreement * @param string $description * @param string $website_url * @param string $password * @param Partner $partner * @param int $templatePartnerId * @return Partner */ private function createNewPartner($partner_name, $contact, $email, $ID_is_for, $SDK_terms_agreement, $description, $website_url, $password = null, $newPartner = null, $templatePartnerId = null) { $secret = md5($this->str_makerand(5, 10, true, false, true)); $admin_secret = md5($this->str_makerand(5, 10, true, false, true)); if (!$newPartner) { $newPartner = new Partner(); } if ($partner_name) { $newPartner->setPartnerName($partner_name); } $newPartner->setAdminSecret($admin_secret); $newPartner->setSecret($secret); $newPartner->setAdminName($contact); $newPartner->setAdminEmail($email); $newPartner->setUrl1($website_url); if ($ID_is_for === "commercial_use" || $ID_is_for === CommercialUseType::COMMERCIAL_USE) { $newPartner->setCommercialUse(true); } else { //($ID_is_for == "non-commercial_use") || $ID_is_for === CommercialUseType::NON_COMMERCIAL_USE) $newPartner->setCommercialUse(false); } $newPartner->setDescription($description); $newPartner->setKsMaxExpiryInSeconds(86400); $newPartner->setModerateContent(false); $newPartner->setNotify(false); $newPartner->setAppearInSearch(mySearchUtils::DISPLAY_IN_SEARCH_PARTNER_ONLY); $newPartner->setIsFirstLogin(true); /* fix drupal5 module partner type */ //var_dump($description); if ($this->partnerParentId) { // this is a child partner of some VAR/partner GROUP $newPartner->setPartnerParentId($this->partnerParentId); $newPartner->setMonitorUsage(PartnerFreeTrialType::NO_LIMIT); $parentPartner = PartnerPeer::retrieveByPK($this->partnerParentId); $newPartner->setPartnerPackage($parentPartner->getPartnerPackage()); } if (substr_count($description, 'Drupal module|')) { $newPartner->setType(102); } $newPartner->save(); // if name was left empty - which should not happen - use id as name if (!$partner_name) { $partner_name = $newPartner->getId(); } $newPartner->setPartnerName($partner_name); $newPartner->setPrefix($newPartner->getId()); $newPartner->setPartnerAlias(md5($newPartner->getId() . 'kaltura partner')); // set default conversion profile for trial accounts if ($newPartner->getType() == Partner::PARTNER_TYPE_KMC) { $newPartner->setDefConversionProfileType(ConversionProfile::DEFAULT_TRIAL_COVERSION_PROFILE_TYPE); } $newPartner->save(); // remove the default criteria from all peers and recreate it with the right partner id myPartnerUtils::resetAllFilters(); myPartnerUtils::applyPartnerFilters($newPartner->getId(), true); $partner_id = $newPartner->getId(); widget::createDefaultWidgetForPartner($partner_id, $this->createNewSubPartner($newPartner)); $fromPartner = PartnerPeer::retrieveByPK($templatePartnerId ? $templatePartnerId : kConf::get("template_partner_id")); if (!$fromPartner) { KalturaLog::log("Template content partner was not found!"); } else { $newPartner->setI18nTemplatePartnerId($templatePartnerId); myPartnerUtils::copyTemplateContent($fromPartner, $newPartner, true); } if ($newPartner->getType() == Partner::PARTNER_TYPE_WORDPRESS) { kPermissionManager::setPs2Permission($newPartner); } $newPartner->setKmcVersion(kConf::get('new_partner_kmc_version')); $newPartner->save(); return $newPartner; }