예제 #1
0
 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();
     }
 }
예제 #2
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);
 }
예제 #3
0
 public function update_password($input)
 {
     $v = new InputValidator($input);
     $v->stringEqual('password2')->validate('password', 'Senha');
     //
     $this->validateToken($input['token'], $v);
     //
     $v->throwException();
     //
     $f = new TableFilter($this->_table, $input);
     $f->crypted()->filter('password');
     $f->null()->filter('password_change_date');
     //
     $this->_dao->update($this->_table, array('id_admin = ?' => $input['token']));
 }
예제 #4
0
 public function insert($input)
 {
     $input['file'] = array($input['file']);
     $v = new InputValidator($input);
     $has_file = $v->upload()->validate('file', 'Foto');
     $v->throwException();
     //
     $f = new TableFilter($this->_table, $input);
     $f->labelCredit()->filter('file');
     $f->newId()->filter($this->_id_photo_item);
     $f->string()->filter($this->_id_photo);
     $f->string()->filter('sequence');
     //
     $mf = new MoveFiles();
     $f->uploaded("/system/uploads/{$this->_photo}/{$input[$this->_id_photo]}/{$this->_photo_item}/{$this->getId()}/file", $has_file, $mf)->filter('file');
     //
     $mf->move();
     $this->_dao->insert($this->_table);
 }
예제 #5
0
 public function update($input)
 {
     $v = new InputValidator($input);
     $v->string()->validate('name', 'Nome');
     $v->stringEmail()->validate('email', 'E-mail');
     $has_avatar = $v->upload()->validate('avatar', 'Avatar');
     $v->throwException();
     //
     $f = new TableFilter($this->_table, $input);
     $f->string()->filter('name');
     $f->string()->filter('email');
     $f->crypted()->filter('password');
     //
     $mf = new MoveFiles();
     $f->uploaded("/system/uploads/admin/{$this->getId()}/avatar", $has_avatar, $mf)->filter('avatar');
     //
     $mf->move();
     //
     $this->dao_update();
     $this->relogin();
 }