Exemple #1
0
 public function sendTweet($msg)
 {
     $input = array('msg' => $msg);
     $v = new InputValidator($input);
     $v->string()->validate('msg', 'Mensagem');
     $v->throwException();
     $consumer_key = $this->_sm_credentials->row['tw_consumer_key'];
     $consumer_secret = $this->_sm_credentials->row['tw_consumer_secret'];
     $access_token = $this->_sm_credentials->row['tw_access_token'];
     $access_secret = $this->_sm_credentials->row['tw_access_secret'];
     //_# ENVIA O TWEET
     try {
         $twitter = new Twitter($consumer_key, $consumer_secret, $access_token, $access_secret);
         $twitter->send($msg);
     } catch (Exception $e) {
         if ($e->getMessage() == 'Status is a duplicate.') {
             throw new Exception('Essa mensagem já foi publicada anteriormente.');
         } else {
             throw new Exception('Erro ao enviar tweet: ' . $e->getMessage());
         }
     }
     $f = new TableFilter($this->_table, $input);
     $f->newId()->filter('id_tweet');
     $f->timestamp()->filter('date');
     $f->string()->filter('msg');
     //
     $this->_dao->insert($this->_table);
     //_# AVISA O MODEL
     $this->_model->sentTweet($this->_table->id_tweet);
 }
 public function recover_password($input)
 {
     $v = new InputValidator($input);
     $v->stringEmail()->validate('email', 'E-mail');
     $v->dbRecord($this->_dao, 'admin')->validate('email', 'E-mail');
     $v->throwException();
     //
     $f = new TableFilter($this->_table, $input);
     $f->timestamp()->filter('password_change_date');
     //
     $this->_dao->update($this->_table, array('email = ?' => $input['email']));
     $this->send_email($input['email']);
 }
 public function post($input)
 {
     try {
         $v = new InputValidator($input);
         $v->string()->validate('name', 'Nome');
         $v->string()->validate('link', 'Link');
         $v->throwException();
         //
         $fileSystem = new FileSystem('tokens');
         $facebookKey = new SocialKeys();
         $facebookKey->setClientId(FACEBOOK_CLIENT_ID);
         $facebookKey->setClientSecret(FACEBOOK_CLIENT_SECRET);
         $facebookKey->setRedirectUri(FACEBOOK_REDIRECT_URL);
         $facebookAuth = new FacebookAuth($facebookKey, $fileSystem);
         $fb = new \Facebook\Facebook(['app_id' => FACEBOOK_CLIENT_ID, 'app_secret' => FACEBOOK_CLIENT_SECRET, 'default_graph_version' => 'v2.7', 'default_access_token' => $facebookAuth->getToken()['access_token']]);
         $facebookPost = new \dinsocial\Facebook\PageFeed($fb);
         $id_post = $facebookPost->postPageFeed(FACEBOOK_PAGE_ID, $input['link'], $input['name'], $input['picture'], $input['description'], $input['message']);
         if ($id_post) {
             $f = new TableFilter($this->_table, $input);
             $f->newId()->filter('id_facepost');
             $f->timestamp()->filter('date');
             $f->string()->filter('name');
             $f->string()->filter('link');
             $f->string()->filter('picture');
             $f->string()->filter('description');
             $f->string()->filter('message');
             //
             $this->_dao->insert($this->_table);
             //_# AVISA O MODEL
             $this->_model->sentPost($this->_table->id_facepost);
         }
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
Exemple #4
0
 public function delete($itens)
 {
     foreach ($itens as $item) {
         $entity = $this->_entities->getEntity($item['name']);
         $entity_id = $entity->getId();
         $entity_title = $entity->getTitle();
         $entity_tbl = $entity->getTbl();
         $entity_sequence = $entity->getSequence();
         $model = $entity->getModel();
         //_# Se ele não possui lixeira, ignora
         if (!$entity->hasTrash()) {
             //ignore
         } else {
             if (count($entity_sequence)) {
                 $seq = new SequenceModel();
                 $seq->changeSequence(array('tbl' => $entity_tbl, 'id' => $item['id'], 'sequence' => 0));
             }
             $tableHistory = $model->getById($item['id']);
             $this->deleteChildrens($entity, $item['id'], $tableHistory);
             $table = new Table($entity_tbl);
             $f = new TableFilter($table, array('is_del' => '1'));
             $f->timestamp()->filter('del_date');
             $f->intval()->filter('is_del');
             $this->_dao->update($table, array($entity_id . ' = ?' => $item['id']));
             $this->log('T', $tableHistory[$entity_title], $table, $tableHistory);
         }
     }
 }