/** * Execute any application/business logic for this component. * * @param sfRequest $request The current sfRequest object * * @return mixed A string containing the view name associated with this action */ function execute($request) { //pas de jenkins => pas de form if (!$this->getJenkins()->isAvailable()) { $this->redirect('jenkins/index'); } if (is_array($buildRequest = $request->getParameter('build'))) { $groupRunId = isset($buildRequest['group_run_id']) ? $buildRequest['group_run_id'] : null; } else { $groupRunId = $request->getParameter('group_run_id'); } $this->forward404If($groupRunId === null, 'group_run_id parameter is required'); $jenkinsGroupRun = JenkinsGroupRunPeer::retrieveByPK($groupRunId); $this->forward404Unless($jenkinsGroupRun instanceof JenkinsGroupRun, sprintf('Can\'t create JenkinsGroupRun with id %s', $groupRunId)); $defaults = array(); if ($request->hasParameter('auto_launch')) { $autoLaunch = $request->getParameter('auto_launch'); if ('on' === $autoLaunch) { $defaults = array('auto_launch' => true); } } else { $defaults = array('auto_launch' => true); } $form = new BuildForm($defaults, array('jenkins' => $this->getJenkins(), 'group_run' => $jenkinsGroupRun)); if (sfRequest::POST === $request->getMethod()) { $form->bind($buildRequest); if ($form->isValid()) { $jobName = $form->getValue('job'); $autoLaunch = 'on' === $form->getValue('auto_launch'); $extraParameters = $form->getValue('parameters'); $jobParameters = array(); if (isset($extraParameters[$jobName])) { $jobParameters = $extraParameters[$jobName]; } //créer les builds $run = new JenkinsRun(); $run->setJenkinsGroupRun($jenkinsGroupRun); $run->setJobName($jobName); $run->encodeParameters($jobParameters); $run->setLaunched($autoLaunch); $run->save(); //launcher les builds if ($autoLaunch) { $run->launch($this->getJenkins(), $jobParameters); $run->computeJobBuildNumber($this->getJenkins(), $this->getUser()); } $this->getUser()->setFlash('info', sprintf('Build [%s] has been added to build branch [%s]', $run->getJobName(), $jenkinsGroupRun->getLabel())); if ($request->hasParameter('add_and_continue')) { $urlRedirect = sprintf('jenkins/addBuild?auto_launch=%s&group_run_id=%s', $autoLaunch ? 'on' : 'off', $jenkinsGroupRun->getId()); } else { $urlRedirect = $this->generateUrl('branch_view', $jenkinsGroupRun); } $this->redirect($urlRedirect); } } $this->setVar('form', $form); $this->setVar('group_run', array('label' => $jenkinsGroupRun->getLabel(), 'git_branch' => $jenkinsGroupRun->getGitBranch(), 'git_branch_slug' => $jenkinsGroupRun->getGitBranchSlug(), 'result' => $jenkinsGroupRun->getResult($this->getJenkins()), 'url' => $this->generateUrl('branch_view', $jenkinsGroupRun))); }
/** * Processes the callback from OAuth provider * * @param sfRequest $request */ public function executeCallback(sfRequest $request) { $this->forward404Unless($request->getParameter('provider')); // user has denied auth'ing the app, don't continue if ($request->hasParameter('error')) { $this->redirect('@homepage'); } $config = sfConfig::get('app_cacophony'); $provider = $request->getParameter('provider'); $this->forward404Unless(in_array($provider, array_keys($config['providers']))); // if OAuth 2.0 if (is_null($config['providers'][$provider]['request_token_url'])) { $this->forward($request->getParameter('module'), 'callback2'); } if (!$this->getUser()->isAuthenticated() || $config['plugin']['allow_multiple_tokens']) { $requestToken = $this->getUser()->getAttribute('requestToken', null, sprintf('sfCacophonyPlugin/%s', $provider)); if ($requestToken) { try { $this->getUser()->setAttribute('accessToken', sfCacophonyOAuth::getAccessToken($provider, $request->getParameter('oauth_token'), $requestToken['oauth_token_secret'], $request->getParameter('oauth_verifier')), sprintf('sfCacophonyPlugin/%s', $provider)); $this->getUser()->getAttributeHolder()->remove('requestToken', null, sprintf('sfCacophonyPlugin/%s', $provider)); // add me to session $me = sfCacophonyOAuth::getMe($provider, $this->getUser()->getAttribute('accessToken', null, sprintf('sfCacophonyPlugin/%s', $provider))); $this->getUser()->setAttribute('me', $me['normalized'], sprintf('sfCacophonyPlugin/%s', $provider)); } catch (Exception $e) { $this->getUser()->setFlash('error', sprintf('Failed to retrieve access token: %s', $e->getMessage())); $this->redirect('@homepage'); } } } else { $this->redirect('@homepage'); } return sfView::NONE; }
/** * Executes joinlist action * * @param sfRequest $request A request object */ public function executeJoinlist($request) { sfConfig::set('sf_nav_type', 'default'); if ($request->hasParameter('id') && $request->getParameter('id') != $this->getUser()->getMemberId()) { sfConfig::set('sf_nav_type', 'friend'); } return parent::executeJoinlist($request); }
/** * * @param sfRequest $request The current sfRequest object * * @return mixed A string containing the view name associated with this action */ function execute($request) { $this->forward404Unless($request->hasParameter('id'), 'id parameter is required'); $jenkinsGroupRun = JenkinsGroupRunPeer::retrieveByPK($request->getParameter('id')); $this->forward404Unless($jenkinsGroupRun instanceof JenkinsGroupRun, sprintf('Can\'t create JenkinsGroupRun with id %s', $request->getParameter('id'))); //suppression du group run (et, en cascade, des runs) $jenkinsGroupRun->delete(null); $this->getUser()->setFlash('info', sprintf('Build branch [%s] has been deleted', $jenkinsGroupRun->getLabel())); $this->redirect('jenkins/index'); }
public static function getSelectedItems(sfRequest $request, $singular = false, $type = false) { if ($singular) { if (!$request->hasParameter('aMediaId')) { return false; } $id = $request->getParameter('aMediaId'); if (!preg_match("/^\\d+\$/", $id)) { return false; } $ids = $id; } else { if (!$request->hasParameter('aMediaIds')) { // User cancelled the operation in the media plugin return false; } $ids = $request->getParameter('aMediaIds'); if (!preg_match("/^(\\d+\\,?)*\$/", $ids)) { // Bad input, possibly a hack attempt return false; } } $ids = explode(",", $ids); if ($ids === false) { // Empty list, nothing to ask for return array(); } $api = new aMediaAPI(); $results = $api->getItems($ids); if ($type !== false) { // This is intended to filter out user attempts to jam video into the list // of ids before we ever got to the API stage $nresults = array(); foreach ($results as $result) { if ($result->type === $type) { $nresults[] = $result; } } $results = $nresults; } return $results; }
/** * @param sfRequest $request The current sfRequest object * * @return mixed|void A string containing the view name associated with this action|void * @throws Exception */ function execute($request) { $jenkins = $this->getJenkins(); if ($request->hasParameter('group_run_id')) { $jenkinsGroupRun = JenkinsGroupRunPeer::retrieveByPK($request->getParameter('group_run_id')); $this->forward404Unless($jenkinsGroupRun instanceof JenkinsGroupRun, sprintf('can\'t create JenkinsGroupRun with id %s', $request->getParameter('group_run_id'))); $jenkinsRuns = $jenkinsGroupRun->getJenkinsRuns(); foreach ($jenkinsRuns as $jenkinsRun) { $this->cancelJenkinsRun($jenkinsRun, $jenkins); } $this->getUser()->setFlash('info', sprintf('All builds of group [%s] have been canceled', $jenkinsGroupRun->getLabel())); $this->redirect($this->generateUrl('branch_view', $jenkinsGroupRun)); } elseif ($request->hasParameter('run_id')) { $jenkinsRun = JenkinsRunPeer::retrieveByPK($request->getParameter('run_id')); $this->forward404Unless($jenkinsRun instanceof JenkinsRun, sprintf('can\'t create JenkinsRun with id %s', $request->getParameter('run_id'))); $this->cancelJenkinsRun($jenkinsRun, $jenkins); $this->redirect($this->generateUrl('branch_view', $jenkinsRun->getJenkinsGroupRun())); } else { throw new Exception('run_id or group_run_id parameter is required'); } }
/** * Processes the current request. * * @param sfRequest A sfRequest instance * * @return Boolean true if the form is valid, false otherwise */ public function process(sfRequest $request) { $data = array('max_per_page' => $request->getParameter('max_per_page', $this->user->getAttribute(self::getMaxPerPageName(), $this->getDefault('max_per_page')))); if ($request->hasParameter(self::$CSRFFieldName)) { $data[self::$CSRFFieldName] = $request->getParameter(self::$CSRFFieldName); } $this->bind($data); if ($isValid = $this->isValid()) { $this->save(); } return $isValid; }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex($request) { if ($request->hasParameter('show')) { $this->getUser()->setAttribute('show', $request->getParameter('show')); } $this->show = $this->getUser()->getAttribute('show', 'people'); $table = $this->getShowTable($this->show); $this->pager = new sfDoctrinePager($table, sfConfig::get('app_max_entities_on_contacts')); $this->pager->setQuery(Doctrine::getTable($table)->getListQuery()); $this->pager->setPage($request->getParameter('page', 1)); $this->pager->init(); }
/** * Processes the current request. * * @param sfRequest A sfRequest instance * * @return Boolean true if the form is valid, false otherwise */ public function process(sfRequest $request) { $data = array('language' => $request->getParameter('language')); if ($request->hasParameter(self::$CSRFFieldName)) { $data[self::$CSRFFieldName] = $request->getParameter(self::$CSRFFieldName); } $this->bind($data); if ($isValid = $this->isValid()) { $this->save(); } return $isValid; }
/** * Executes user action * * @param sfRequest $request A request object */ public function executeUser($request) { if (!$request->hasParameter('id')) { $this->member = $this->getUser()->getMember(); } else { $this->member = $this->getRoute()->getObject(); $relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($this->getUser()->getMemberId(), $this->member->getId()); $this->forward404If($relation && $relation->isAccessBlocked()); } $this->blogRssCacheList = Doctrine::getTable('BlogRssCache')->findByMemberId($this->member->getId(), sfConfig::get('app_blog_action_size')); if (!count($this->blogRssCacheList)) { return sfView::ALERT; } }
/** * Executes login action * * @param sfRequest $request A request object */ public function executeLogin($request) { $this->getUser()->logout(); $this->forms = $this->getUser()->getAuthForms(); if ($request->hasParameter('authMode')) { if ($uri = $this->getUser()->login()) { $this->redirectIf($this->getUser()->hasCredential('SNSRegisterBegin'), 'member/registerInput'); $this->redirectIf($this->getUser()->hasCredential('SNSRegisterFinish'), $this->getUser()->getRegisterEndAction()); $this->redirectIf($this->getUser()->hasCredential('SNSMember'), $uri); } return sfView::ERROR; } $routing = sfContext::getInstance()->getRouting(); if ('homepage' !== $routing->getCurrentRouteName() && 'login' !== $routing->getCurrentRouteName()) { $this->getUser()->setFlash('notice', 'Please login'); } return sfView::SUCCESS; }
/** * Executes index action * * @param sfRequest $request A request object **/ public function executeIndex($request) { $user = $this->sf_user; $this->user_id = $this->sf_user_id; $branch_id = $this->sf_branch_id; $this->is_branch_owner = $this->sf_is_branch_owner; $this->owner_branch_ids = $this->sf_owner_branch_ids; $user->setAttribute('type', ''); $user->setAttribute('keyword', ''); $option = ''; $this->keepstay = ''; $user->setAttribute('user_client_status_closed', false); if ($request->hasParameter('search')) { $search_criteria = $request->getParameter('search', array()); $this->keepstay = $search_criteria['type']; if (array_key_exists($search_criteria['type'], $search_criteria)) { $option = $search_criteria[$search_criteria['type']]; } else { $option = $search_criteria['keyword']; } $user->setAttribute('type', $this->keepstay); $user->setAttribute('keyword', $option); } $this->search_value = $option; $staff_users = array(); $staff_users[0] = 'Select a Staff'; $sales_lists = array(); $sales_lists[0] = 'Select a Sales'; $this->client_ranks = clientRankPeer::getClientOpportunityListForSearch($branch_id); $admin_users = $this->getUser()->getBranchAdminUsers(); foreach ($admin_users as $admin_user) { $staff_users[$admin_user->getId()] = $admin_user->getProfile()->getFullname(); } $sales_users = $this->getUser()->getBranchOfficeStaffUsers(); foreach ($sales_users as $sales_user) { $sales_lists[$sales_user->getId()] = $sales_user->getProfile()->getFullname(); } $this->created_by = $staff_users; $this->sales = $sales_lists; }
/** * DOCUMENT ME * @param sfRequest $request * @return mixed */ public function executeEdit(sfRequest $request) { $this->logMessage("====== in aSlideshowSlotActions::executeEdit", "info"); if ($request->getParameter('aMediaCancel')) { return $this->redirectToPage(); } $this->editSetup(); if ($request->hasParameter('aMediaIds')) { $ids = preg_split('/,/', $request->getParameter('aMediaIds')); $q = Doctrine::getTable('aMediaItem')->createQuery('m')->select('m.*')->whereIn('m.id', $ids)->andWhere('m.type = "image"'); // Let the query preserve order for us $items = aDoctrine::orderByList($q, $ids)->execute(); $this->slot->unlink('MediaItems'); $links = aArray::getIds($items); $this->slot->link('MediaItems', $links); // This isn't a normal form submission, but the act of selecting items for a // slideshow implies we picked the 'selected' radio button, so just save 'form' as if // that choice had been saved normally $this->slot->value = serialize(array('form' => array('type' => 'selected'), 'order' => $links)); return $this->editSave(); } }
/** * Executes search action * * @param sfRequest $request A request object */ public function executeSearch($request) { $params = array('keyword' => $request->getParameter('keyword'), 'target' => $request->getParameter('target', 'in_community'), 'type' => $request->getParameter('type', 'topic')); $this->form = new PluginCommunityTopicSearchForm(); $this->form->bind($params); if ('event' === $request->getParameter('type')) { $table = Doctrine::getTable('CommunityEvent'); $this->link_to_detail = 'communityEvent/show?id=%d'; $this->type = 'event'; } else { $table = Doctrine::getTable('CommunityTopic'); $this->link_to_detail = 'communityTopic/show?id=%d'; $this->type = 'topic'; } $this->communityId = $request->getParameter('id'); $this->pageUrl = '@communityTopic_search'; if (!$request->hasParameter('id')) { unset($this->form['target']); $this->pageUrl .= '_all'; } else { $this->pageUrl .= '?id=' . $this->communityId; } $q = $table->getSearchQuery($request->getParameter('id'), $request->getParameter('target'), $request->getParameter('keyword')); $this->pager = $table->getResultListPager($q, $request->getParameter('page')); $this->isResult = false; if (null !== $request->getParameter('keyword') || null !== $request->getParameter('target') || null !== $request->getParameter('type')) { $this->isResult = true; } return sfView::SUCCESS; }
/** * Connection test logic. * * Overload this method to customize how a connection is determined. * * @todo Add support for configuring a request parameter that should * _not_ be present. * * @param sfRequest $request * @param string $page * @param array $param * * @return bool */ protected function doConnect(sfRequest $request, $page, $param) { if (sfConfig::get('sf_logging_enabled')) { sfContext::getInstance()->getLogger()->info(sprintf('{%s} connect %s:%s', __CLASS__, $this->name, $page)); } $match = true; foreach ($param as $key => $value) { // if value is null (~ in yml), this parameter must be absent, // otherwise the value must match the request parameter if (is_null($value) && $request->hasParameter($key) || $request->getParameter($key) !== $value) { $match = false; break; } } return $match; }
/** * Executes configUID action * * @param sfRequest $request A request object */ public function executeConfigUID($request) { $option = array('member' => $this->getUser()->getMember()); $this->passwordForm = new sfOpenPNEPasswordForm(array(), $option); $mobileUid = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId('mobile_uid', $this->getUser()->getMemberId()); $this->isSetMobileUid = $mobileUid && $mobileUid->getValue(); $this->isDeletableUid = (int) opConfig::get('retrieve_uid') < 2 && $this->isSetMobileUid; if ($request->isMethod('post')) { $this->passwordForm->bind($request->getParameter('password')); if ($this->passwordForm->isValid()) { if ($request->hasParameter('update')) { if (!$request->getMobileUID()) { $this->getUser()->setFlash('error', 'Your mobile UID was not registered.'); $this->redirect('member/configUID'); } $memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId('mobile_uid', $this->getUser()->getMemberId()); if (!$memberConfig) { $memberConfig = new MemberConfig(); $memberConfig->setMember($this->getUser()->getMember()); $memberConfig->setName('mobile_uid'); } $memberConfig->setValue($request->getMobileUID()); $memberConfig->save(); $this->getUser()->setFlash('notice', 'Your mobile UID was set successfully.'); $this->redirect('member/configUID'); } elseif ($request->hasParameter('delete') && $this->isDeletableUid) { $mobileUid->delete(); $this->getUser()->setFlash('notice', 'Your mobile UID was deleted successfully.'); $this->redirect('member/configUID'); } } } return sfView::SUCCESS; }
/** * @param sfRequest $request The current sfRequest object * @return mixed A string containing the view name associated with this action */ function execute($request) { $userId = $this->getUser()->getUserId(); $jenkins = $this->getJenkins(); $sortParams = explode('_', $request->getParameter('sort')); $sortType = 'none'; $sortDirection = ''; if (count($sortParams) == 1) { $sortType = strlen($sortParams[0]) ? $sortParams[0] : 'none'; } elseif (count($sortParams) == 2) { list($sortType, $sortDirection) = $sortParams; } if ($request->hasParameter('git_branch_slug')) { $groupRun = JenkinsGroupRunPeer::retrieveBySfGuardUserIdAndGitBranchSlug($userId, $request->getParameter('git_branch_slug')); $this->forward404If(null === $groupRun, sprintf('Unable to find build branch with branch name %s ', $request->getParameter('git_branch_slug'))); $currentGroupId = $groupRun->getId(); } else { $currentGroupId = $request->getParameter('group_run_id'); } $order = $sortDirection == 'desc' ? Criteria::DESC : Criteria::ASC; $query = new JenkinsGroupRunQuery(); $query->findBySfGuardUserId($userId); switch ($sortType) { case 'date': $query->orderByDate($order); break; case 'label': $query->orderByLabel($order); break; default: $query->orderByDate(Criteria::DESC); break; } $groupRuns = $query->find(); $dataGroupRuns = array(); foreach ($groupRuns as $groupRun) { if (null === $currentGroupId) { $currentGroupId = $groupRun->getId(); } /** @var JenkinsGroupRun $groupRun */ $result = $groupRun->getResult($jenkins); $dataGroupRuns[$groupRun->getId()] = array('label' => $groupRun->getLabel(), 'git_branch' => $groupRun->getGitBranch(), 'git_branch_slug' => $groupRun->getGitBranchSlug(), 'date' => $groupRun->getDate('Y-m-d H:i:s'), 'result' => $result, 'result_weight' => $groupRun->getResultWeight($result), 'url_view' => $this->generateUrl('branch_view', $groupRun) . '/sort/' . $sortType . '_' . $sortDirection); } if ($sortType == 'result') { $method = $sortDirection == 'asc' ? 'sortGroupRunsByResultAsc' : 'sortGroupRunsByResultDesc'; uasort($dataGroupRuns, array($this, $method)); } $currentGroupRun = JenkinsGroupRunPeer::retrieveByPK($currentGroupId); $sortMenu = $partial_url_for_sort_direction = $branch_view_url = null; if (null !== $currentGroupRun) { $sortMenu = array('label' => array('label' => 'Name', 'url' => $this->generateUrl('branch_view', $currentGroupRun) . '/sort/label_' . $sortDirection), 'date' => array('label' => 'Creation date', 'url' => $this->generateUrl('branch_view', $currentGroupRun) . '/sort/date_' . $sortDirection), 'result' => array('label' => 'Status', 'url' => $this->generateUrl('branch_view', $currentGroupRun) . '/sort/result_' . $sortDirection)); $branch_view_url = $this->generateUrl('branch_view', $currentGroupRun); $partial_url_for_sort_direction = sprintf('%s/sort/%s_', $this->generateUrl('branch_view', $currentGroupRun), $sortType); } $this->setVar('group_runs', $dataGroupRuns); $this->setVar('current_group_run_id', $currentGroupId); $this->setVar('sort_type', $sortType); $this->setVar('sort_direction', $sortDirection); $this->setVar('sort_menu', $sortMenu); $this->setVar('branch_view_url', $branch_view_url); $this->setVar('partial_url_for_sort_direction', $partial_url_for_sort_direction); $this->setVar('enabled_popover', $this->getUser()->getProfile()->getPopoverEnabled()); }
public function executeLogin(sfRequest $request) { /* Consumer key from twitter */ $consumer_key = sfConfig::get('app_sfTwitterAuth_consumer_key'); $consumer_secret = sfConfig::get('app_sfTwitterAuth_consumer_secret'); $user = $this->getUser(); $module = $request->getParameter('module'); $action = $request->getParameter('action'); if ($module !== 'sfTwitterAuth') { // We were forwarded here to force a login $user->setAttribute('sfTwitterAuth_after', "{$module}/{$action}"); } /* Set state if previous session */ $state = $user->getAttribute('sfTwitterAuth_oauth_state'); /* If oauth_token is missing get it */ if ($request->hasParameter('oauth_token') && $state === 'start') { $user->setAttribute('sfTwitterAuth_oauth_state', $state = 'returned'); } /* * Switch based on where in the process you are * * 'default': Get a request token from twitter for new user * 'returned': The user has authorized the app on twitter */ switch ($state) { default: /* Create TwitterOAuth object with app key/secret */ $to = new TwitterOAuth($consumer_key, $consumer_secret); /* Request tokens from twitter */ $tok = $to->getRequestToken(); /* Save tokens for later */ $user->setAttribute('sfTwitterAuth_oauth_request_token', $token = $tok['oauth_token']); $user->setAttribute('sfTwitterAuth_oauth_request_token_secret', $tok['oauth_token_secret']); $user->setAttribute('sfTwitterAuth_oauth_state', "start"); /* Build the authorization URL */ $request_link = $to->getAuthorizeURL($token); return $this->redirect($request_link); break; case 'returned': /* If the access tokens are already set skip to the API call */ if (!$user->getAttribute('sfTwitterAuth_oauth_access_token') && !$user->getAttribute('sfTwitterAuth_oauth_access_token_secret')) { /* Create TwitterOAuth object with app key/secret and token key/secret from default phase */ $to = new TwitterOAuth($consumer_key, $consumer_secret, $user->getAttribute('sfTwitterAuth_oauth_request_token'), $user->getAttribute('sfTwitterAuth_oauth_request_token_secret')); /* Request access tokens from twitter */ $tok = $to->getAccessToken(); /* Save the access tokens. These could be saved in a database as they don't currently expire. But our goal here is just to authenticate the session. */ $user->setAttribute('sfTwitterAuth_oauth_access_token', $tok['oauth_token']); $user->setAttribute('sfTwitterAuth_oauth_access_token_secret', $tok['oauth_token_secret']); } /* Create TwitterOAuth with app key/secret and user access key/secret */ $to = new TwitterOAuth($consumer_key, $consumer_secret, $user->getAttribute('sfTwitterAuth_oauth_access_token'), $user->getAttribute('sfTwitterAuth_oauth_access_token_secret')); /* Run request on twitter API as user. */ $result = $to->OAuthRequest('https://twitter.com/account/verify_credentials.xml', array(), 'GET'); $xml = simplexml_load_string($result); $username = $xml->xpath("descendant::screen_name"); if (is_array($username) && count($username)) { $username = (string) $username[0]; $guardUser = Doctrine_Query::create()->from('sfGuardUser u')->where('username = ?', array($username))->fetchOne(); if (!$guardUser) { // Make a new user here $guardUser = new sfGuardUser(); $guardUser->setUsername($username); // Set a secure, random sfGuard password to ensure that this // account is not wide open if conventional logins are permitted $guid = ""; for ($i = 0; $i < 8; $i++) { $guid .= sprintf("%x", mt_rand(0, 15)); } $guardUser->setPassword($guid); $guardUser->save(); } $user->signIn($guardUser); $after = $user->getAttribute('sfTwitterAuth_after'); if (!$after) { $after = "@homepage"; } return $this->redirect($after); } else { $user->setAttribute('sfTwitterAuth_oauth_request_token', null); $user->setAttribute('sfTwitterAuth_request_token_secret', null); $user->setAttribute('sfTwitterAuth_oauth_state', null); $user->setAttribute('sfTwitterAuth_oauth_access_token', null); $user->setAttribute('sfTwitterAuth_oauth_access_token_secret', null); $this->redirect('sfTwitterAuth/failed'); } break; } }
/** * Executes delete action * * @param sfRequest $request A request object */ public function executeDelete($request) { if ($this->id && !$this->isEditCommunity) { $this->forward('default', 'secure'); } if ($request->isMethod('post')) { if ($request->hasParameter('is_delete')) { $community = Doctrine::getTable('Community')->find($this->id); if ($community) { $community->delete(); } $this->redirect('community/search'); } else { $this->redirect('community/home?id=' . $this->id); } } $this->community = Doctrine::getTable('Community')->find($this->id); }
/** * Execute any application/business logic for this component. * * @param sfRequest $request The current sfRequest object * * @return mixed A string containing the view name associated with this action */ function execute($request) { //pas de jenkins => pas de form if (!$this->getJenkins()->isAvailable()) { $this->redirect('jenkins/index'); } $default = array('sf_guard_user_id' => $this->getUser()->getUserId()); if ($request->hasParameter('from_group_run_id')) { //duplication de la configuration $groupRun = JenkinsGroupRunPeer::retrieveByPK($request->getParameter('from_group_run_id')); if (null !== $groupRun) { $default = $groupRun->buildDefaultFormValue($this->getJenkins(), $default); } } if ($request->hasParameter('branch')) { $branch = $request->getParameter('branch'); $default['git_branch'] = $branch; $default['label'] = $branch; } $form = new GroupRunForm($default, array('jenkins' => $this->getJenkins(), 'sf_guard_user_id' => $this->getUser()->getUserId())); if (sfRequest::POST === $request->getMethod()) { $form->bind($request->getParameter('group_run')); if ($form->isValid()) { $autoLaunch = 'on' === $form->getValue('auto_launch'); //création du group run $runGroup = new JenkinsGroupRun(); $runGroup->setSfGuardUserId($this->getUser()->getUserId()); $runGroup->setDate(new DateTime()); $runGroup->setGitBranch($form->getValue('git_branch')); $runGroup->setLabel($form->getValue('label')); $runGroup->save(); $nbJobs = 0; foreach ($form->getValue('builds') as $jobName => $jobInfo) { if (!$jobInfo['job_name']) { continue; } $parameters = array(); if (isset($jobInfo['parameters'])) { $parameters = $jobInfo['parameters']; } //créer les builds $run = new JenkinsRun(); $run->setJenkinsGroupRun($runGroup); $run->setJobName($jobName); $run->encodeParameters($parameters); $run->setLaunched($autoLaunch); $run->save(); $nbJobs++; if ($autoLaunch) { //launcher les builds $run->launch($this->getJenkins(), $parameters); $run->computeJobBuildNumber($this->getJenkins(), $this->getUser()); } } if (0 === $nbJobs) { $this->getUser()->setFlash('info', sprintf('Build branch [%s] has been created', $runGroup->getLabel())); } else { $label = 1 === $nbJobs ? 'Job has ' : 'Jobs have '; $this->getUser()->setFlash('info', $label . ($autoLaunch ? "been launched" : "been registered in delayed list")); } $this->redirect($this->generateUrl('branch_view', $runGroup)); } } $views = $this->getViews($this->getJenkins()); $defaultView = $this->getJenkins()->getPrimaryView(); $this->setVar('form', $form); $this->setVar('view_by_jobs', $this->buildViewByJobs($this->getJenkins())); $this->setVar('views', $views); $this->setVar('default_active_view', null === $defaultView ? null : $defaultView->getName()); }
public function executeEditVideo(sfRequest $request) { $this->forward404Unless(aMediaTools::userHasUploadPrivilege()); $item = null; $this->slug = false; if ($request->hasParameter('slug')) { $item = $this->getItem(); $this->slug = $item->getSlug(); } if ($item) { $this->forward404Unless($item->userHasPrivilege('edit')); } $this->item = $item; $subclass = 'aMediaVideoYoutubeForm'; $embed = false; $parameters = $request->getParameter('a_media_item'); if (aMediaTools::getOption('embed_codes') && ($item && strlen($item->embed) || isset($parameters['embed']))) { $subclass = 'aMediaVideoEmbedForm'; $embed = true; } $this->form = new $subclass($item); if ($parameters) { $files = $request->getFiles('a_media_item'); $this->form->bind($parameters, $files); do { // first_pass forces the user to interact with the form // at least once. Used when we're coming from a // YouTube search and we already technically have a // valid form but want the user to think about whether // the title is adequate and perhaps add a description, // tags, etc. if ($this->hasRequestParameter('first_pass') || !$this->form->isValid()) { break; } // TODO: this is pretty awful factoring, I should have separate actions // and migrate more of this code into the model layer if ($embed) { $embed = $this->form->getValue("embed"); $thumbnail = $this->form->getValue('thumbnail'); // The base implementation for saving files gets confused when // $file is not set, a situation that our code tolerates as useful // because if you're updating a record containing an image you // often don't need to submit a new one. unset($this->form['thumbnail']); $object = $this->form->getObject(); if ($thumbnail) { $object->preSaveImage($thumbnail->getTempName()); } $this->form->save(); if ($thumbnail) { $object->saveImage($thumbnail->getTempName()); } } else { $url = $this->form->getValue("service_url"); // TODO: migrate this into the model and a // YouTube-specific support class if (!preg_match("/youtube.com.*\\?.*v=([\\w\\-\\+]+)/", $url, $matches)) { $this->serviceError = true; break; } // YouTube thumbnails are always JPEG $format = 'jpg'; $videoid = $matches[1]; $feed = "http://gdata.youtube.com/feeds/api/videos/{$videoid}"; $entry = simplexml_load_file($feed); // get nodes in media: namespace for media information $media = $entry->children('http://search.yahoo.com/mrss/'); // get a more canonical video player URL $attrs = $media->group->player->attributes(); $canonicalUrl = $attrs['url']; // get biggest video thumbnail foreach ($media->group->thumbnail as $thumbnail) { $attrs = $thumbnail->attributes(); if (!isset($widest) || $attrs['width'] + 0 > $widest['width'] + 0) { $widest = $attrs; } } // The YouTube API doesn't report the original width and height of // the video stream, so we use the largest thumbnail, which in practice // is the same thing on YouTube. if (isset($widest)) { $thumbnail = $widest['url']; // Turn them into actual numbers instead of weird XML wrapper things $width = $widest['width'] + 0; $height = $widest['height'] + 0; } if (!isset($thumbnail)) { $this->serviceError = true; break; } // Grab a local copy of the thumbnail, and get the pain // over with all at once in a predictable way if // the service provider fails to give it to us. $thumbnailCopy = aFiles::getTemporaryFilename(); if (!copy($thumbnail, $thumbnailCopy)) { $this->serviceError = true; break; } $object = $this->form->getObject(); $new = !$object->getId(); $object->preSaveImage($thumbnailCopy); $object->setServiceUrl($url); $this->form->save(); $object->saveImage($thumbnailCopy); unlink($thumbnailCopy); } return $this->redirect("aMedia/resumeWithPage"); } while (false); } }
/** * Executes subAdminRequest action * * @param sfRequest $request A request object */ public function executeSubAdminRequest($request) { $this->forward404Unless($this->isAdmin); $this->member = Doctrine::getTable('Member')->find($request->getParameter('member_id')); $this->forward404Unless($this->member); $this->community = Doctrine::getTable('Community')->find($this->id); $this->communityMember = Doctrine::getTable('CommunityMember')->retrieveByMemberIdAndCommunityId($this->member->getId(), $this->id); $this->forward404If($this->communityMember->getIsPre()); $this->forward404If($this->communityMember->hasPosition(array('admin', 'admin_confirm', 'sub_admin', 'sub_admin_confirm'))); $this->form = new opChangeCommunityAdminRequestForm(); if ($request->hasParameter('admin_request')) { $this->form->bind($request->getParameter('admin_request')); if ($this->form->isValid()) { Doctrine::getTable('CommunityMember')->requestSubAdmin($this->member->getId(), $this->id); $this->redirect('@community_memberManage?id=' . $this->id); } } return sfView::INPUT; }
public function executeInfo(sfRequest $request) { $params = array(); $this->validateAPIKey(); if ($request->hasParameter('ids')) { $ids = $request->getParameter('ids'); if (!preg_match("/^(\\d+\\,?)*\$/", $ids)) { // Malformed request $this->jsonResponse('malformed'); } $ids = explode(",", $ids); if ($ids === false) { $ids = array(); } $params['ids'] = $ids; } $numbers = array("width", "height", "minimum-width", "minimum-height", "aspect-width", "aspect-height"); foreach ($numbers as $number) { if ($request->hasParameter($number)) { $n = $request->getParameter($number) + 0; if ($number < 0) { $n = 0; } $params[$number] = $n; } } $strings = array("tag", "search", "type", "user"); foreach ($strings as $string) { if ($request->hasParameter($string)) { $params[$string] = $request->getParameter($string); } } if (isset($params['tag'])) { $this->logMessage("ZZZZZ got tag: " . $params['tag'], "info"); } $query = aMediaItemTable::getBrowseQuery($params); $countQuery = clone $query; $countQuery->offset(0); $countQuery->limit(0); $result = new StdClass(); $result->total = $countQuery->count(); if ($request->hasParameter('offset')) { $offset = max($request->getParameter('offset') + 0, 0); $query->offset($offset); } if ($request->hasParameter('limit')) { $limit = max($request->getParameter('limit') + 0, 0); $query->limit($limit); } $absolute = !!$request->getParameter('absolute', false); $items = $query->execute(); $nitems = array(); foreach ($items as $item) { $info = array(); $info['type'] = $item->getType(); $info['id'] = $item->getId(); $info['slug'] = $item->getSlug(); $info['width'] = $item->getWidth(); $info['height'] = $item->getHeight(); $info['format'] = $item->getFormat(); $info['title'] = $item->getTitle(); $info['description'] = $item->getDescription(); $info['credit'] = $item->getCredit(); $info['tags'] = array_keys($item->getTags()); // The embed HTML we suggest is a template in which they can // replace _WIDTH_ and _HEIGHT_ and _c-OR-s_ with // whatever they please // Absolute URL option $info['embed'] = $item->getEmbedCode('_WIDTH_', '_HEIGHT_', '_c-OR-s_', '_FORMAT_', $absolute); // The image URL we suggest is a template in which they can // replace _WIDTH_, _HEIGHT_, _c-OR-s_ and _FORMAT_ with // whatever they please $controller = sfContext::getInstance()->getController(); // Must use keys that will be acceptable as property names, no hyphens! // original refers to the original file, if we ever had it // (images and PDFs). If you ask for the original of a video, you // currently get the media plugin's copy of the best available still. $info['original'] = $controller->genUrl("@a_media_original?" . http_build_query(array("slug" => $item->getSlug(), "format" => $item->getFormat()), $absolute)); $info['image'] = $controller->genUrl("a_media_image?" . http_build_query(array("slug" => $item->getSlug(), "width" => "1000001", "height" => "1000002", "format" => "jpg", "resizeType" => "c")), $absolute); $info['image'] = str_replace(array("1000001", "1000002", ".c."), array("_WIDTH_", "_HEIGHT_", "._c-OR-s_."), $info['image']); $info['image'] = preg_replace("/\\.jpg\$/", "._FORMAT_", $info['image']); if ($info['type'] === 'video') { $info['serviceUrl'] = $item->getServiceUrl(); } $nitems[] = $info; } $result->items = $nitems; $this->jsonResponse('ok', $result); }
/** * Executes search action * * @param sfRequest $request A request object */ public function executeSearch($request) { $params = $request->getParameter('member', array()); if ($request->hasParameter('search_query')) { $params = array_merge($params, array('name' => $request->getParameter('search_query', ''))); } $this->filters = new opMemberProfileSearchForm(); $this->filters->bind($params); if (!isset($this->size)) { $this->size = 20; } $this->pager = new sfDoctrinePager('Member', $this->size); $q = $this->filters->getQuery()->orderBy('id desc'); $this->pager->setQuery($q); $this->pager->setPage($request->getParameter('page', 1)); $this->pager->init(); return sfView::SUCCESS; }