Esempio n. 1
0
 public function generateTweet()
 {
     $entity_tbl = $this->_entity->getTbl();
     $entity_title = $this->_entity->getTitle();
     $entity_id = $this->_entity->getId();
     $select = new Select($entity_tbl);
     $select->addField($entity_title, 'title');
     $select->addField('uri');
     $select->addField('short_link');
     $select->where(array("{$entity_id} = ?" => $this->getId()));
     $result = $this->_dao->select($select);
     if (!count($result)) {
         throw new Exception('Registro não encontrado');
     }
     $title = $result[0]['title'];
     $title = LimitChars::filter($title, 100, '...');
     if ($result[0]['short_link']) {
         $url = $result[0]['short_link'];
     } else {
         $url = URL . $result[0]['uri'];
     }
     //shorten url
     try {
         $bitly = new Bitly(BITLY);
         $bitly->shorten($url);
         $short_url = $bitly->getShortUrl();
     } catch (Exception $e) {
         //mute exception, just continue with big url
         $short_url = $url;
     }
     $tweet = "{$title} - Saiba mais {$short_url}";
     return $tweet;
 }
Esempio n. 2
0
 public function filter($field)
 {
     $title = $this->getValue($this->_title);
     $uri = $this->getValue($field);
     $this->_id = substr($this->_id, 0, 4);
     $uri = $uri == '' ? Uri::format($title) : Uri::format($uri);
     $uri = LimitChars::filter($uri, 80, '');
     if ($this->_prefix != '') {
         if ($this->_format_prefix) {
             $this->_prefix = '/' . Uri::format($this->_prefix);
         } else {
             $this->_prefix = '/' . $this->_prefix;
         }
     }
     if ($this->_id != '') {
         $this->_table->uri = "{$this->_prefix}/{$uri}-{$this->_id}/";
     } else {
         $this->_table->uri = "{$this->_prefix}/{$uri}/";
     }
 }