コード例 #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;
 }
コード例 #2
0
ファイル: ShortenerLink.php プロジェクト: dindigital/din
 public function filter($field)
 {
     if (URL && BITLY && $this->_table->uri) {
         $url = URL . $this->_table->uri;
         try {
             $bitly = new Bitly(BITLY);
             if (defined('BITLY_DOMAIN') && BITLY_DOMAIN) {
                 $bitly->setDomain(BITLY_DOMAIN);
             }
             $bitly->shorten($url);
             $this->_table->short_link = (string) $bitly;
         } catch (\Exception $e) {
             //die($e->getMessage());
         }
     }
 }