Example #1
0
 public function test_normalize()
 {
     $tests = array('FOO' => 'foo', '   foo' => 'foo', 'foo  ' => 'foo', ' foo ' => 'foo', 'foo-bar' => 'foobar', ' FOo-bar ' => 'foobar');
     foreach ($tests as $tag => $normalized_tag) {
         $this->assertEqual($normalized_tag, Tag::normalize($tag));
     }
 }
Example #2
0
 public function removeTag($question, $tag)
 {
     $c = new Criteria();
     $c->add(QuestionTagPeer::QUESTION_ID, $question->getId());
     $c->add(QuestionTagPeer::USER_ID, $this->getId());
     $c->add(QuestionTagPeer::NORMALIZED_TAG, Tag::normalize($tag));
     QuestionTagPeer::doDelete($c);
 }
 /**
  * Execute this filter.
  *
  * @param FilterChain The filter chain.
  *
  * @return void
  * @throws <b>FilterException</b> If an erro occurs during execution.
  */
 public function execute($filterChain)
 {
     // execute this filter only once
     if (sfConfig::get('app_universe') && $this->isFirstCall()) {
         // is there a tag in the hostname?
         $request = $this->getContext()->getRequest();
         $hostname = $request->getHost();
         if (!preg_match($this->getParameter('host_exclude_regex'), $hostname) && ($pos = strpos($hostname, '.'))) {
             $tag = Tag::normalize(substr($hostname, 0, $pos));
             // add a permanent tag constant
             sfConfig::set('app_permanent_tag', $tag);
             // add a custom stylesheet
             $this->getContext()->getResponse()->addStylesheet($tag);
             // is the tag a culture?
             if (is_readable(sfConfig::get('sf_app_i18n_dir') . '/messages.' . strtolower($tag) . '.xml')) {
                 $this->getContext()->getUser()->setCulture(strtolower($tag));
             } else {
                 $this->getContext()->getUser()->setCulture('en');
             }
         }
     }
     // execute next filter
     $filterChain->execute();
 }
Example #4
0
 public function executeShow()
 {
     $this->question_pager = QuestionPeer::getPopularByTag($this->getRequestParameter('tag'), $this->getRequestParameter('page', 1));
     $this->getResponse()->setTitle('askeet! &raquo; question tagged ' . Tag::normalize($this->getRequestParameter('tag')));
 }
Example #5
0
 public function setTag($v)
 {
     parent::setTag($v);
     $this->setNormalizedTag(Tag::normalize($v));
 }
Example #6
0
 public static function deleteSpam($moderator, $tag, $question_id = null)
 {
     if ($question_id === null) {
         $tags = self::getByNormalizedTag($tag);
     } else {
         $c = new Criteria();
         $c->add(self::NORMALIZED_TAG, Tag::normalize($tag));
         $c->add(self::QUESTION_ID, $question_id);
         $tags = self::doSelect($c);
     }
     $con = Propel::getConnection();
     try {
         $con->begin();
         foreach ($tags as $tag) {
             $user = $tag->getUser();
             $user->setDeletions($user->getDeletions() + 1);
             $user->save();
             $tag->delete();
         }
         $con->commit();
         $log = 'moderator "%s" deleted tag "%s"';
         $log = sprintf($log, $moderator->getNickname(), $tag->getNormalizedTag());
         sfContext::getInstance()->getLogger()->warning($log);
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
 }
Example #7
0
 public function hasTag($tag)
 {
     $c = new Criteria();
     $c->add(QuestionTagPeer::QUESTION_ID, $this->getId());
     $c->add(QuestionTagPeer::NORMALIZED_TAG, Tag::normalize($tag));
     return QuestionTagPeer::doSelectOne($c) ? true : false;
 }