public static function checkAuthorized() { self::storeInstance(); if (OAuthRequestVerifier::requestIsSigned()) { try { $req = new OAuthRequestVerifier(); $userId = $req->verify(); // If we have an user_id, then login as that user (for this request) if ($userId) { $user = SfGuardUserPeer::retrieveByPK($userId); sfContext::getInstance()->getUser()->signin($user); } } catch (OAuthException $e) { sfContext::getInstance()->getLogger()->err("oauthSecurityManager::checkAuthorized exception"); sfContext::getInstance()->getLogger()->err("Message: " + $e->getMessage()); $this->sendNotAuthorized(); } } else { sfContext::getInstance()->getLogger()->err("oauthSecurityManager::checkAuthorized request not signed"); $this->sendNotAuthorized(); } return $userId; }
public function executeSearch(sfWebRequest $request) { $culture = $this->getUser()->getCulture(); $this->page = $this->getRequestParameter('page', 1); $tag = $request->getParameter("tag", false); $tag = str_replace("_2E_", ".", $tag); if ($tag) { $this->q = "#{$tag}"; } else { $this->q = $request->getParameter("q"); } $request->setAttribute("q", $this->q); $resultsArray = array(); $cl = $this->resetSphinxClient(); $needle = $this->q; $this->ext = ""; if (strlen($needle) > 0 && strpos($needle, '#') === 0) { $this->ext = "_tag"; $needle = substr($needle, 1); } else { $needle = SfVoUtil::stripAccents($this->q); } $this->politicoCounts = false; $this->partidoCounts = false; $this->propuestaCounts = false; if ($needle) { if ($this->ext == "_tag") { $cl->SetMatchMode(SPH_MATCH_PHRASE); $cl->SetSortMode(SPH_SORT_EXTENDED, "cnt DESC"); $this->politicoCounts = array(); $this->partidoCounts = array(); $this->propuestaCounts = array(); $indexes = "partido_tag_{$culture}, politico_tag_{$culture}, propuesta_tag_{$culture}"; $this->res = $cl->Query($needle, $indexes); if ($this->res !== false) { $this->total = $this->res['total']; $this->totalFound = $this->res['total_found']; $cl->SetLimits(($this->page - 1) * $this->limit, $this->limit); $this->res = $cl->Query($needle, $indexes); } } else { $cl->SetFieldWeights(array('abreviatura_partido' => 5, 'nombre' => 5, 'apellidos' => 5, 'alias' => 5, 'titulo' => 5, 'nombre_insti' => 8, 'nombre_ele' => 9)); $cl->SetSortMode(SPH_SORT_EXPR, "@weight + ( 1 * votes/max_votes )"); $indexes = "politico_{$culture}, partido_{$culture},propuesta_{$culture}, institucion_{$culture}, usuario, eleccion_{$culture}"; $this->res = $cl->Query($needle, $indexes); if ($this->res !== false) { $this->total = $this->res['total']; $this->totalFound = $this->res['total_found']; $cl->SetLimits(($this->page - 1) * $this->limit, $this->limit); $this->res = $cl->Query($needle, $indexes); } } if ($this->res !== false && isset($this->res["matches"]) && is_array($this->res["matches"])) { foreach ($this->res["matches"] as $match) { //echo "<pre>";print_r( $match );echo "</pre>"; switch ($match['attrs']['type']) { case 1: if ($this->ext == "_tag") { $this->politicoCounts[$match['attrs']['politico_id']] = $match['attrs']['cnt']; $resultsArray[] = PoliticoPeer::retrieveByPK($match['attrs']['politico_id']); } else { $resultsArray[] = PoliticoPeer::retrieveByPK($match['id']); } break; case 2: if ($this->ext == "_tag") { $this->partidoCounts[$match['attrs']['partido_id']] = $match['attrs']['cnt']; $resultsArray[] = PartidoPeer::retrieveByPK($match['attrs']['partido_id']); } else { $resultsArray[] = PartidoPeer::retrieveByPK($match['id']); } break; case 3: if ($this->ext == "_tag") { $this->propuestaCounts[$match['attrs']['propuesta_id']] = $match['attrs']['cnt']; $resultsArray[] = PropuestaPeer::retrieveByPK($match['attrs']['propuesta_id']); } else { $resultsArray[] = PropuestaPeer::retrieveByPK($match['id']); } break; case 101: $resultsArray[] = InstitucionPeer::retrieveByPK($match['id']); break; case 102: $resultsArray[] = SfGuardUserPeer::retrieveByPK($match['id']); break; case 103: $resultsArray[] = ConvocatoriaPeer::retrieveByPK($match['id']); break; } } } } $this->results = $resultsArray; $this->title = sfContext::getInstance()->getI18N()->__('"%1%" en Voota', array('%1%' => $this->q)); $descStr = ""; foreach ($resultsArray as $idx => $result) { if ($idx < 3) { $descStr .= ($descStr ? ', ' : '') . $result; } } $this->response->addMeta('Description', sfContext::getInstance()->getI18N()->__('Resultados de la búsqueda "%1%" en Voota: %2%, ...', array('%1%' => $this->q, '%2%' => $descStr))); $this->response->setTitle($this->title); }
public function executeFeed(sfWebRequest $request) { $vanity = $request->getParameter('username'); $this->f = $request->getParameter('f'); $culture = $this->getUser()->getCulture(); $c = new Criteria(); $c->add(SfGuardUserProfilePeer::VANITY, $vanity, Criteria::EQUAL); $userProfile = SfGuardUserProfilePeer::doSelectOne($c); $this->forward404Unless($userProfile); $this->user = $userProfile->getsfGuardUser(); if (!$this->user->getIsActive() && is_numeric($userProfile->getFacebookUid())) { $user = SfGuardUserPeer::retrieveByPK($userProfile->getFacebookUid()); $this->forward404Unless($user); $this->redirect('perfil/show?username='******'%1% en Voota.es', array('%1%' => $this->user)); $descripcion = SfVoUtil::cutToLength($userProfile->getPresentacion(), 155, '...', true); $description = $descripcion ? $descripcion : sfContext::getInstance()->getI18N()->__('Votos y opiniones de %1% sobre políticos y partidos de España', array('%1%' => trim($this->user) ? $this->user : $this->user->getProfile()->getVanity())); $feed = new sfRssFeed(); $feed->setTitle($title); $feed->setLanguage($culture); $feed->setSubtitle($description); $feed->setDescription($description); $feed->setLink('perfil/show?username='******'ca' ? "cat" : $culture; $feed->setAuthorName("Voota.{$domainExt}"); $feedImage = new sfFeedImage(); $feedImage->setLink('perfil/show?username='******'/usuarios/cc_' . $this->user->getProfile()->getImagen()); $feedImage->setTitle($this->user); $feed->setImage($feedImage); foreach ($reviews as $review) { $item = new sfFeedItem(); $entityText = ""; if (!$review->getSfReviewType()) { $tmpReview = $review->getSfReviewRelatedBySfReviewId(); $entityText = sfContext::getInstance()->getI18N()->__('Otra opinión sobre') . ' '; } else { $tmpReview = $review; } $sfReviewType = SfReviewTypePeer::retrieveByPk($tmpReview->getSfReviewTypeId()); $peer = $sfReviewType->getModel() . 'Peer'; $entity = $peer::retrieveByPk($tmpReview->getEntityId()); $entityText .= $entity; $item->setTitle(sfContext::getInstance()->getI18N()->__('%1%, voota %2%.', array('%1%' => $entityText, '%2%' => $review->getValue() == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor')))); $item->setLink('sfReviewFront/show?id=' . SfVoUtil::reviewPermalink($review)); $item->setAuthorName($review->getSfGuardUser()); $item->setPubdate($review->getCreatedAt('U')); $item->setUniqueId($review->getId()); $avatar = S3Voota::getImagesUrl() . '/usuarios/cc_s_' . $review->getSfGuardUser()->getProfile()->getImagen(); $text = $culture == $review->getCulture() || !$review->getCulture() ? $review->getText() : ''; $img = $review->getSfGuardUser()->getProfile()->getImagen() ? "<img src=\"{$avatar}\" alt =\"" . $review->getSfGuardUser() . "\" /> " : ""; $content = "{$text}"; $item->setDescription($content); $feed->addItem($item); } $this->feed = $feed; }