예제 #1
0
파일: SfVoUtil.php 프로젝트: voota/voota
 public static function highlightWords($string, $q)
 {
     if (!$q) {
         return;
     }
     $words = explode(' ', trim($q));
     $expw = '';
     foreach ($words as $idx => $word) {
         $expw .= ($idx == 0 ? '' : '|') . self::voDecode($word);
     }
     $initString = $string;
     $aWord = SfVoUtil::voDecode($word);
     $exp = "/[a-z0-9" . self::ACCENTS . "]*.{0," . self::HIGHLIGHT_LENGTH . "}({$expw}).{0," . self::HIGHLIGHT_LENGTH . "}[a-z0-9" . self::ACCENTS . "]*/is";
     if (preg_match($exp, SfVoUtil::voDecode($string), $matches, PREG_OFFSET_CAPTURE)) {
         $shorStr = $matches[0][0];
         $iniPos = strpos(SfVoUtil::voDecode($string), $shorStr);
         $shortLen = strlen($shorStr);
     } else {
         $iniPos = 0;
         $shortLen = self::HIGHLIGHT_LENGTH * 2;
     }
     $initString = ($iniPos > 0 ? '...' : '') . utf8_encode(substr(utf8_decode($string), $iniPos, $shortLen) . ($shortLen < strlen(utf8_decode($string)) ? '...' : ''));
     $aString = $initString;
     if (preg_match_all("/{$expw}/is", SfVoUtil::voDecode($initString), $matches, PREG_OFFSET_CAPTURE)) {
         $aString = "";
         foreach ($matches[0] as $idx => $match) {
             $initPos = $idx == 0 ? 0 : $match[1];
             $endPos = isset($matches[0][$idx + 1]) ? $matches[0][$idx + 1][1] - $match[1] - strlen($match[0]) : strlen(utf8_decode($initString)) - $match[1];
             $aString .= ($idx == 0 ? substr(utf8_decode($initString), $initPos, $match[1]) : '') . '<span class="highlight_word">' . substr(utf8_decode($initString), $match[1], strlen($match[0])) . '</span>' . substr(utf8_decode($initString), $match[1] + strlen($match[0]), $endPos);
         }
         $aString = utf8_encode($aString);
     }
     return $aString;
 }
예제 #2
0
 protected function politico($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $c = new Criteria();
     //$c->add(PoliticoPeer::ID, 1, Criteria::EQUAL);
     if ($options['min-id'] != "0") {
         $c->add(PoliticoPeer::ID, $options['min-id'], Criteria::GREATER_EQUAL);
     }
     $politicos = PoliticoPeer::doSelect($c);
     foreach ($politicos as $politico) {
         if ($politico->getVanity() == '' || $options['force'] == '1') {
             if ($options['with-name'] == "1") {
                 $newVanityString = $politico->getNombre() . '-' . $politico->getApellidos();
             } else {
                 $newVanityString = $politico->getApellidos();
             }
             $vanityUrl = SfVoUtil::encodeVanity($newVanityString);
             $c2 = new Criteria();
             $c2->add(PoliticoPeer::VANITY, "{$vanityUrl}%", Criteria::LIKE);
             $c2->add(PoliticoPeer::ID, $politico->getId(), Criteria::NOT_EQUAL);
             $politicosLikeMe = PoliticoPeer::doSelect($c2);
             $counter = 0;
             foreach ($politicosLikeMe as $politicoLikeMe) {
                 $aVanity = str_replace("-", "\\-", $vanityUrl);
                 if (preg_match(SfVoUtil::voDecode("/^{$vanityUrl}\\-([0-9]*)\$/is"), SfVoUtil::voDecode($politicoLikeMe->getVanity()), $matches)) {
                     if ($counter < 1 + $matches[1]) {
                         $counter = 1 + $matches[1];
                     } else {
                         $counter++;
                     }
                 } else {
                     $counter++;
                 }
             }
             $newVanity = "{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}");
             echo "Setting vanity from " . $politico->getVanity() . " to  " . $newVanity . " ...\n";
             $politico->setVanity($newVanity);
             $politico->save();
         }
     }
 }
예제 #3
0
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $s3 = new S3Voota();
     $c = new Criteria();
     //$c->add(PoliticoPeer::ID, 1, Criteria::EQUAL);
     $politicos = PoliticoPeer::doSelect($c);
     foreach ($politicos as $politico) {
         $vanity = $politico->getVanity();
         if ($vanity != ($new = SfVoUtil::fixVanityChars($vanity))) {
             while (preg_match("/(.*)-\$/is", $new, $m, PREG_OFFSET_CAPTURE)) {
                 $new = $m[1][0];
             }
             $c2 = new Criteria();
             $c2->add(PoliticoPeer::VANITY, "{$new}%", Criteria::LIKE);
             $c2->add(PoliticoPeer::ID, $politico->getId(), Criteria::NOT_EQUAL);
             $politicosLikeMe = PoliticoPeer::doSelect($c2);
             $counter = 0;
             foreach ($politicosLikeMe as $politicoLikeMe) {
                 $aVanity = str_replace("-", "\\-", $new);
                 if (preg_match(SfVoUtil::voDecode("/^{$new}\\-([0-9]*)\$/is"), SfVoUtil::voDecode($politicoLikeMe->getVanity()), $matches)) {
                     if ($counter < 1 + $matches[1]) {
                         $counter = 1 + $matches[1];
                     } else {
                         $counter++;
                     }
                 } else {
                     $counter++;
                 }
             }
             $new = "{$new}" . ($counter == 0 ? '' : "-{$counter}");
             echo "politico:{$vanity} ";
             echo "cambia a:{$new}\n";
             $politico->setVanity($new);
             $politico->save();
         }
     }
     $usuarios = SfGuardUserPeer::doSelect($c);
     foreach ($usuarios as $usuario) {
         $vanity = $usuario->getProfile()->getVanity();
         if ($vanity != SfVoUtil::fixVanityChars($vanity)) {
             echo "usuario:{$vanity} ({$usuario})\n";
             $usuario->getProfile()->setVanity(SfVoUtil::fixVanityChars($vanity));
             $usuario->getProfile()->save();
         }
     }
     $partidos = PartidoPeer::doSelect($c);
     foreach ($partidos as $partido) {
         $vanity = $partido->getAbreviatura();
         if ($vanity != SfVoUtil::fixVanityChars($vanity)) {
             echo "partido:{$vanity}\n";
         }
     }
     // Instituciones
     $instituciones = InstitucionI18nPeer::doSelect($c);
     foreach ($instituciones as $institucion) {
         $vanity = $institucion->getVanity();
         if ($vanity != ($new = SfVoUtil::fixVanityChars($vanity))) {
             echo "institucion:{$vanity}\n";
             $institucion->setVanity($new);
             $institucion->save();
             echo "cambia a:{$new}\n";
         }
     }
 }