예제 #1
0
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     $vanity = isset($taintedValues['vanity']) ? $taintedValues['vanity'] : false;
     $titulo = isset($taintedValues['titulo']) ? $taintedValues['titulo'] : false;
     $descripcion = isset($taintedValues['descripcion']) ? $taintedValues['descripcion'] : false;
     $id = isset($taintedValues['id']) ? $taintedValues['id'] : false;
     if ($titulo) {
         $taintedValues['titulo'] = SfVoUtil::cutToLength($taintedValues['titulo'], 80);
     }
     if ($descripcion) {
         $taintedValues['descripcion'] = SfVoUtil::cutToLength($taintedValues['descripcion'], 600);
     }
     if ($vanity) {
         $taintedValues['vanity'] = SfVoUtil::fixVanityChars($vanity);
     } else {
         if (!$id) {
             $taintedValues['vanity'] = SfVoUtil::fixVanityChars($taintedValues['titulo']);
         }
     }
     if (!$this->isNew()) {
         if (isset($taintedValues['enlace'])) {
             if (is_null($taintedValues['enlace']['url']) || strlen($taintedValues['enlace']['url']) === 0) {
                 unset($this->embeddedForms['enlace'], $taintedValues['enlace']);
                 $this->validatorSchema['enlace'] = new sfValidatorPass();
             } else {
                 $this->embeddedForms['enlace']->getObject()->setPropuesta($this->getObject());
             }
         }
         if (isset($taintedValues['institucion'])) {
             if (is_null($taintedValues['institucion']['institucion_id']) || strlen($taintedValues['institucion']['institucion_id']) === 0) {
                 unset($this->embeddedForms['institucion'], $taintedValues['institucion']);
                 $this->validatorSchema['institucion'] = new sfValidatorPass();
             } else {
                 $this->embeddedForms['institucion']->getObject()->setPropuesta($this->getObject());
             }
         }
     }
     parent::bind($taintedValues, $taintedFiles);
 }
예제 #2
0
파일: Politico.php 프로젝트: voota/voota
 public function getLongName()
 {
     return SfVoUtil::cutToLength("" . $this->__toString(), 35) . ($this->getPartido() ? " (" . $this->getPartido() . ")" : '');
 }
예제 #3
0
파일: sfCutTest.php 프로젝트: voota/voota
<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
$tests = array('ábcd' => array('length' => 10, 'ext' => '', 'fullWords' => false), 'ábcd2' => array('length' => 1, 'ext' => '', 'fullWords' => false), 'ábcd3' => array('length' => 2, 'ext' => '', 'fullWords' => false), 'ábcd4' => array('length' => 3, 'ext' => '', 'fullWords' => false), 'aácd5' => array('length' => 1, 'ext' => '', 'fullWords' => false), 'La nueva reforma de la ley de tráfico pretende, en palabras de Rubalcaba (al menos eso dice la carta de mi buzón), conseguir que nuestras carreteras sean cada vez más seguras.
  
  Para ello basan su campaña en tres pilares básicos:
  
  - Más sencilla
  - Más fácil
  - Más justa
  
  Adjunto la la ley en pdf y enlace a la página correspondiente.
  
  La nueva reforma de la ley de tráfico pretende, en palabras de Rubalcaba (al menos eso dice la carta de mi buzón), conseguir que nuestras carreteras sean cada vez más seguras.
  
  Para ello basan su campaña en tres pilares básicos:
  
  - Más sencilla
  - Más fácil
  - Más justa
  
  Adjunto la la ley en pdf y enlace a la página correspondiente.' => array('length' => 182, 'ext' => '', 'fullWords' => false));
foreach ($tests as $string => $attributes) {
    echo "{$string} (" . $attributes['length'] . "): [" . SfVoUtil::cutToLength($string, $attributes['length'], $attributes['ext'], $attributes['fullWords']) . "]\n";
}
예제 #4
0
 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;
 }
예제 #5
0
 public function executeEditDoc(sfWebRequest $request)
 {
     $op = $request->getParameter("op", "d");
     $id = $request->getParameter("id", 0);
     $titulo = $request->getParameter("titulo");
     $descripcion = $request->getParameter("descripcion");
     $this->propuesta = PropuestaPeer::retrieveByPk($id);
     $this->forward404Unless($this->propuesta);
     $files = $request->getFiles();
     if ($op == 'et') {
         $this->propuesta->setTitulo(SfVoUtil::cutToLength($titulo, 80, '', false));
         $this->propuesta->save();
         $this->redirect("propuesta/show?id=" . $this->propuesta->getVanity());
     } elseif ($op == 'ed') {
         $this->propuesta->setDescripcion(SfVoUtil::cutToLength($descripcion, 600, '', false));
         $this->propuesta->save();
         $this->redirect("propuesta/show?id=" . $this->propuesta->getVanity());
     } elseif ($op == 'ep') {
         $img = $files['img'];
         if ($img) {
             $arr = array_reverse(explode(".", $img['name']));
             $ext = strtolower($arr[0]);
             if (!$ext || $ext == "") {
                 $ext = "png";
             }
             $docName = SfVoUtil::fixVanityChars($arr[1]);
             $docName .= "-" . sprintf("%04d", rand(0, 999));
             $docName .= ".{$ext}";
             $fileName = sfConfig::get('sf_upload_dir') . '/propuestas/' . $docName;
             move_uploaded_file($img['tmp_name'], $fileName);
             $s = new S3Voota();
             $s->createFromFile('propuestas', $fileName);
             $this->propuesta->setImagen($docName);
             $this->propuesta->save();
         }
         $this->redirect("propuesta/show?id=" . $this->propuesta->getVanity());
     } else {
         switch ($op) {
             case 's':
                 return 'Saved';
                 break;
             case 'd':
                 break;
             case 'f':
                 $this->propuesta->setDoc(null);
                 $this->propuesta->setDocSize(null);
                 $this->propuesta->save();
                 return 'Form';
             case 'u':
                 $doc = $files['doc'];
                 if ($doc) {
                     $arr = array_reverse(explode(".", $doc['name']));
                     $ext = strtolower($arr[0]);
                     if (!$ext || $ext == "") {
                         $ext = "png";
                     }
                     $docName = SfVoUtil::fixVanityChars($arr[1]);
                     $docName .= "-" . sprintf("%04d", rand(0, 999));
                     $docName .= ".{$ext}";
                     $fileName = sfConfig::get('sf_upload_dir') . '/docs/' . $docName;
                     move_uploaded_file($doc['tmp_name'], $fileName);
                     $s = new S3Voota();
                     $s->createDocFromFile('docs', $fileName);
                     $this->propuesta->setDoc($docName);
                     $this->propuesta->setDocSize($s->getSize("docs/{$docName}"));
                     $this->propuesta->save();
                     echo "0";
                     die;
                 }
                 return 'Form';
         }
     }
 }
예제 #6
0
 public function executeShow(sfWebRequest $request)
 {
     $abreviatura = $request->getParameter('id');
     $culture = $this->getUser()->getCulture("es");
     $this->institucion = $request->getParameter("institucion");
     if ($this->institucion == '') {
         $this->institucion = "0";
     }
     $c = new Criteria();
     $c->add(PartidoPeer::ABREVIATURA, $abreviatura, Criteria::EQUAL);
     $this->partido = PartidoPeer::doSelectOne($c);
     $this->forward404Unless($this->partido);
     $this->forward404Unless($this->partido->getIsActive());
     if ($this->partido->getAbreviatura() != $abreviatura) {
         $this->redirect('partido/show?id=' . $this->partido->getAbreviatura(), 301);
     }
     // Estabamos vootando antes del login ?
     $sfr_status = $this->getUser()->getAttribute('sfr_status', false, 'sf_review');
     if ($sfr_status) {
         $aSfrStatus = array();
         foreach ($sfr_status as $key => $value) {
             $aSfrStatus[$key] = $value;
         }
         $this->sfr_status = $aSfrStatus;
         $request->setAttribute('sfr_status', $aSfrStatus);
         $this->getUser()->setAttribute('sfr_status', false, 'sf_review');
     } else {
         $this->getUser()->setAttribute('sfr_status', false, 'sf_review');
         $this->sfr_status = false;
     }
     if ($this->partido->getImagen() != '') {
         $imageFileName = $this->partido->getImagen();
     } else {
         $imageFileName = "p_unknown.png";
     }
     $this->image = "cc_{$imageFileName}";
     $pu = $this->getUser()->getAttribute('pageU');
     $pd = $this->getUser()->getAttribute('pageD');
     $c = $this->getUser()->getAttribute('review_c');
     if ($c != '' && $pu != '') {
         $resU = BaseSfReviewManager::NUM_REVIEWS * ($pu - 1);
         $this->pageU = $pu;
     } else {
         $resU = BaseSfReviewManager::NUM_REVIEWS;
         $this->pageU = 2;
     }
     if ($c != '' && $pd != '') {
         $resD = BaseSfReviewManager::NUM_REVIEWS * ($pd - 1);
         $this->pageD = $pd;
     } else {
         $resD = BaseSfReviewManager::NUM_REVIEWS;
         $this->pageD = 2;
     }
     $id = $this->partido->getId();
     $this->positives = SfReviewManager::getReviewsByEntityAndValue($request, Partido::NUM_ENTITY, $id, 1, $resU);
     $this->negatives = SfReviewManager::getReviewsByEntityAndValue($request, Partido::NUM_ENTITY, $id, -1, $resD);
     $positiveCount = $this->positives->getNbResults();
     $negativeCount = $this->negatives->getNbResults();
     $this->getUser()->setAttribute('pageU', '');
     $this->getUser()->setAttribute('pageD', '');
     $this->totalCount = $positiveCount + $negativeCount;
     if ($this->totalCount > 0) {
         $this->positivePerc = intval($positiveCount * 100 / $this->totalCount);
         $this->negativePerc = 100 - $this->positivePerc;
     } else {
         $this->positivePerc = 0;
         $this->negativePerc = 0;
     }
     // Enlaces
     $c = new Criteria();
     $rCriterion = $c->getNewCriterion(EnlacePeer::CULTURE, null, Criteria::ISNULL);
     $rCriterion->addOr($c->getNewCriterion(EnlacePeer::CULTURE, $this->getUser()->getCulture()));
     $rCriterion->addOr($c->getNewCriterion(EnlacePeer::CULTURE, ''));
     $c->add($rCriterion);
     $c->add(EnlacePeer::PARTIDO_ID, $id);
     $c->addAscendingOrderByColumn(EnlacePeer::ORDEN);
     $this->activeEnlaces = EnlacePeer::doSelect($c);
     $this->twitterUser = FALSE;
     foreach ($this->activeEnlaces as $enlace) {
         if (preg_match("/twitter\\.com\\/#!\\/(.*)\$/is", $enlace->getUrl(), $matches)) {
             $this->twitterUser = $matches[1];
             break;
         }
         if (preg_match("/twitter\\.com\\/(.*)\$/is", $enlace->getUrl(), $matches)) {
             $this->twitterUser = $matches[1];
             break;
         }
     }
     // Politicos mas votados
     $c = new Criteria();
     $c->addJoin(array(PoliticoPeer::ID, PoliticoI18nPeer::CULTURE), array(PoliticoI18nPeer::ID, "'{$culture}'"), Criteria::LEFT_JOIN);
     $c->add(PoliticoPeer::VANITY, null, Criteria::ISNOTNULL);
     $c->add(PoliticoPeer::PARTIDO_ID, $this->partido->getId());
     $c->addDescendingOrderByColumn(PoliticoPeer::SUMU);
     $c->addAscendingOrderByColumn(PoliticoPeer::SUMD);
     $this->politicos = new sfPropelPager('Politico', 6);
     $this->politicos->setCriteria($c);
     $this->politicos->init();
     // Lista de instituciones
     $c = new Criteria();
     $c->addJoin(InstitucionPeer::ID, PoliticoInstitucionPeer::INSTITUCION_ID);
     $c->addJoin(PoliticoInstitucionPeer::POLITICO_ID, PoliticoPeer::ID);
     $c->addJoin(PoliticoPeer::PARTIDO_ID, PartidoPeer::ID);
     $c->add(PoliticoPeer::PARTIDO_ID, $this->partido->getId());
     $c->add(InstitucionPeer::IS_MAIN, true);
     $c->setDistinct();
     $c->addAscendingOrderByColumn(InstitucionPeer::ORDEN);
     $this->instituciones = InstitucionPeer::doSelect($c);
     // Lista de listas
     $this->listasGenerales = false;
     $this->listasAutonomicas = false;
     $this->listasMunicipales = false;
     foreach ($this->partido->getListas() as $lista) {
         //$lista->getCircunscripcion()->getGeo()
         foreach ($lista->getConvocatoria()->getEleccion()->getEleccionInstitucions() as $insti) {
             $geo = $insti->getInstitucion()->getGeo();
             if ($geo->getId() == 1) {
                 $this->listasGenerales = true;
             } elseif ($geo->getGeoRelatedByGeoId()->getId() == 1) {
                 $this->listasAutonomicas = true;
             } elseif ($geo->getGeoRelatedByGeoId()->getGeoRelatedByGeoId()->getId() == 1) {
             } elseif ($geo->getGeoRelatedByGeoId()->getGeoRelatedByGeoId()->getGeoRelatedByGeoId()->getId() == 1) {
                 $this->listasMunicipales = true;
             }
         }
     }
     $this->pageTitle = $this->partido->getNombre() . " (" . $this->partido->getAbreviatura() . ")";
     $this->title = $this->pageTitle . ' - Voota';
     $this->response->addMeta('Title', $this->title);
     $descripcion = $this->partido->getAbreviatura() . ": " . sfContext::getInstance()->getI18N()->__('presentación, opiniones de usuarios a favor y en contra, políticos mejor valorados y enlaces. ', array()) . SfVoUtil::cutToLength($this->partido->getPresentacion(), 140, '...', true);
     $this->response->addMeta('Descripcion', $descripcion);
     // Listas de electorales
     $convocatoriaActiva = sfConfig::get('sf_convocatoria_activa');
     $this->convocatoria = ConvocatoriaPeer::retrieveByPk($convocatoriaActiva);
     $c = new Criteria();
     $c->add(ListaPeer::PARTIDO_ID, $this->partido->getId());
     $c->add(ListaPeer::CONVOCATORIA_ID, $convocatoriaActiva);
     $c->addJoin(ListaPeer::CIRCUNSCRIPCION_ID, CircunscripcionPeer::ID);
     $c->addJoin(CircunscripcionPeer::GEO_ID, GeoPeer::ID);
     $c->addAscendingOrderByColumn(GeoPeer::NOMBRE);
     $this->listas = ListaPeer::doSelect($c);
     /* paginador */
     $this->partidosPager = EntityManager::getPager($this->partido);
     /* / paginador */
     // Feed
     $request->setAttribute('rssTitle', $this->title . " Feed RSS");
     $request->setAttribute('rssFeed', 'partido/feed?id=' . $this->partido->getVanity());
 }
예제 #7
0
 public function sendTasks(sfWebRequest $request)
 {
     $tw_publish = $request->getParameter("tw_publish", 0);
     $t = $request->getParameter("t", false);
     $v = $request->getParameter("v", false);
     $e = $request->getParameter("e", false);
     $review_text = $request->getParameter("review_text", false);
     $this->updateSums($request);
     if ($t) {
         $type = SfReviewTypePeer::retrieveByPk($t);
         $peer = $type->getModel() . "Peer";
         $entity = call_user_func("{$peer}::retrieveByPk", $e);
     } else {
         $review = SfReviewPeer::retrieveByPk($request->getParameter('e'));
         if ($typeId = $review->getSfReviewTypeId()) {
             $type = SfReviewTypePeer::retrieveByPK($typeId);
             $peer = $type->getModule() . 'Peer';
             $entity = call_user_func("{$peer}::retrieveByPk", $review->getEntityId());
         }
     }
     $msg = "";
     if ($tw_publish && TwitterManager::verify($this->getUser())) {
         switch ($t) {
             case Politico::NUM_ENTITY:
                 $entityUrl = sfContext::getInstance()->getController()->genUrl("politico/show?id=" . $entity->getVanity(), true);
                 $msg = sfContext::getInstance()->getI18N()->__('Voto  %1% de %2% en @Voota:  %3%', array('%1%' => $v == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor'), '%2%' => $entity, '%3%' => TwitterManager::shorten($entityUrl)));
                 break;
             case Partido::NUM_ENTITY:
                 $entityUrl = sfContext::getInstance()->getController()->genUrl("partido/show?id=" . $entity->getAbreviatura(), true);
                 $msg = sfContext::getInstance()->getI18N()->__('Voto %1% del partido %2% en @Voota: %3%', array('%1%' => $v == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor'), '%2%' => $entity->getAbreviatura(), '%3%' => TwitterManager::shorten($entityUrl)));
                 break;
             case Propuesta::NUM_ENTITY:
                 $entityUrl = sfContext::getInstance()->getController()->genUrl("propuesta/show?id=" . $entity->getVanity(), true);
                 $msg = sfContext::getInstance()->getI18N()->__('Voto %1% de la propuesta "%2%" en @Voota: %3%', array('%1%' => $v == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor'), '%2%' => SfVoUtil::cutToLength($entity->getTitulo(), 60, '...', true), '%3%' => TwitterManager::shorten($entityUrl)));
                 break;
             case "":
                 $entityUrl = sfContext::getInstance()->getController()->genUrl($type->getModule() . "/show?id=" . $entity->getVanity(), true);
                 $msg = sfContext::getInstance()->getI18N()->__('Vooto %1% de una opinión sobre %2% en @Voota: %3%', array('%1%' => $v == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor'), '%2%' => $entity, '%3%' => TwitterManager::shorten($entityUrl)));
                 break;
         }
         TwitterManager::post($this->getUser(), $msg);
     }
     // Enviar email
     if (!$t) {
         //echo $request->getParameter('i');
         $user = $review->getsfGuardUser();
         if ($user->getProfile()->getMailsComentarios()) {
             if ($typeId) {
                 $user->getProfile()->setCodigo(util::generateUID());
                 $user->getProfile()->save();
                 $mailBody = $this->getPartial('reviewLeftMailBody', array('nombre' => $user->getProfile()->getNombre(), 'usuario' => $review->getAnonymous() ? sfContext::getInstance()->getI18N()->__('anónimo (está en su derecho)') : $this->getUser()->getProfile()->getNombre() . ' ' . $this->getUser()->getProfile()->getApellidos(), 'entity' => $typeId == Propuesta::NUM_ENTITY ? "\"{$entity}\"" : $entity, 'texto_ori' => $review->getText(), 'comentario' => $request->getParameter('review_text'), 'vanity' => $entity->getVanity(), 'codigo' => $user->getProfile()->getCodigo(), 'voto' => $request->getParameter('v'), 'module' => $entity->getModule()));
                 VoMail::send(sfContext::getInstance()->getI18N()->__('Tu vooto sobre %1% tiene un comentario', array('%1%' => $entity)), $mailBody, $user->getUsername(), array('*****@*****.**' => 'no-reply Voota'), true);
             }
         }
     }
 }
예제 #8
0
function cutToLength($str, $length = 35, $ext = '...', $fullWords = false)
{
    return SfVoUtil::cutToLength($str, $length, $ext, $fullWords);
}
예제 #9
0
 public static function postReview($userId, $typeId, $entityId, $value, $text = false, $entity = false, $rm = false, $fb = '?', $source = '', $anonymous = '?', $tw = '?')
 {
     $prevValue = false;
     $guessAnonymous = $anonymous && $anonymous == '?' ? true : false;
     $guessFB = $fb && $fb == '?' ? true : false;
     $guessTW = $tw && $tw == '?' ? true : false;
     if ($guessAnonymous) {
         $user = sfGuardUserPeer::retrieveByPK($userId);
         if ($user) {
             $anonymous = $user->getProfile()->getAnonymous();
         }
     }
     if (!$entityId || !$value) {
         throw new Exception("Not enough parameters.");
     }
     if ($value != -1 && $value != 1) {
         throw new Exception("Invalid data for 'value'.");
     }
     // Check if already exists
     $c = new Criteria();
     if (!$typeId) {
         $c->add(SfReviewPeer::SF_REVIEW_ID, $entityId);
     } else {
         $c->add(SfReviewPeer::ENTITY_ID, $entityId);
     }
     $c->add(SfReviewPeer::SF_GUARD_USER_ID, $userId);
     $c->add(SfReviewPeer::SF_REVIEW_TYPE_ID, $typeId ? $typeId : null);
     $review = SfReviewPeer::doSelectOne($c);
     if (!$review) {
         $review = new SfReview();
         if (!$typeId) {
             $review->setSfReviewId($entityId);
         } else {
             $review->setEntityId($entityId);
         }
         $review->setSfReviewTypeId($typeId ? $typeId : null);
         $review->setSfGuardUserId($userId);
         $review->setCreatedAt(new DateTime());
         $review->setSource($source);
     } else {
         if ($rm && $value == $review->getValue() && $review->getIsActive()) {
             $review->setIsActive(false);
         } else {
             $review->setIsActive(true);
         }
         $review->setModifiedAt(new DateTime());
     }
     $review->setValue($value);
     if ($text) {
         $aText = SfVoUtil::cutToLength($text, self::MAX_LENGTH, '');
         $aText = strip_tags($aText);
         $review->setText($aText);
     }
     $review->setSfReviewStatusId(1);
     $review->setIpAddress($_SERVER['REMOTE_ADDR']);
     $review->setCookie(sfContext::getInstance()->getRequest()->getCookie('symfony'));
     $review->setCulture(sfContext::getInstance()->getUser()->getCulture());
     if (!$guessFB) {
         $review->setToFb($fb);
     }
     if (!$guessTW) {
         $review->setToTw($tw);
     }
     if (!$guessAnonymous || $review->isNew()) {
         $review->setAnonymous($anonymous);
     }
     try {
         $review->save();
         if (!$typeId) {
             $parentReview = SfReviewPeer::retrieveByPk($entityId);
             $parentReview->setBalance(SfReviewManager::getBalanceByReviewId($entityId));
             $parentReview->save();
         }
         if (!$entity) {
             if (!$typeId) {
                 $aEntityId = $parentReview->getEntityId();
                 $aTypeId = $parentReview->getSfReviewTypeId();
             } else {
                 $aTypeId = $typeId;
                 $aEntityId = $entityId;
             }
             $reviewType = SfReviewTypePeer::retrieveByPK($aTypeId);
             $peer = $reviewType->getModel() . 'Peer';
             $entity = $peer::retrieveByPK($aEntityId);
         }
         $entity->updateCalcs();
         $entity->save();
     } catch (Exception $e) {
         throw new Exception('Error writing review.');
     }
     return $review->getIsActive() ? $review : false;
 }