예제 #1
0
 /**
  * Validate input data from captcha
  * @param string|null $data
  * @return bool
  */
 public static function validate($data = null)
 {
     // nevertheless what we got in our model, recaptcha is suck and don't allow to change response field name
     $data = App::$Request->get('g-recaptcha-response');
     // make validation
     $request = Request::create('https://www.google.com/recaptcha/api/siteverify', 'GET', ['secret' => self::$secret, 'response' => $data, 'remoteip' => App::$Request->getClientIp()]);
     // make request and parse response
     $url = $request->getSchemeAndHttpHost() . $request->getRequestUri();
     $response = Url::download($url);
     $object = json_decode($response);
     return $object->success;
 }
예제 #2
0
 /**
  * Try to download and parse remote avatar
  * @param string $url
  * @param int $userId
  */
 protected function parseAvatar($url, $userId)
 {
     // check if user is defined
     if ((int) $userId < 1) {
         return;
     }
     // check remote image extension
     $imageExtension = Str::lastIn($url, '.', true);
     if (!Arr::in($imageExtension, ['png', 'gif', 'jpg', 'jpeg'])) {
         return;
     }
     // try to get image binary data
     $imageContent = Url::download($url);
     if ($imageContent === null || Str::likeEmpty($imageContent)) {
         return;
     }
     // write image to filesystem
     $imagePath = '/upload/user/avatar/original/' . $userId . '.' . $imageExtension;
     $write = File::write($imagePath, $imageContent);
     if ($write === false) {
         return;
     }
     // try to write and resize file
     try {
         $fileObject = new FileObject(root . $imagePath);
         $avatarUpload = new FormAvatarUpload();
         $avatarUpload->resizeAndSave($fileObject, $userId, 'small');
         $avatarUpload->resizeAndSave($fileObject, $userId, 'medium');
         $avatarUpload->resizeAndSave($fileObject, $userId, 'big');
     } catch (\Exception $e) {
         if (App::$Debug) {
             App::$Debug->addException($e);
         }
     }
 }
예제 #3
0
파일: Main.php 프로젝트: phpffcms/ffcms
 /**
  * Download news from ffcms.org server and show it with caching & saving
  * @return string|null
  */
 public function actionNews()
 {
     $this->setJsonHeader();
     // get ffcms news if cache is not available
     $news = null;
     if (App::$Cache->get('download.ffcms.api.news.' . $this->lang) !== null) {
         $news = App::$Cache->get('download.ffcms.api.news.' . $this->lang);
     } else {
         $news = Url::download('https://ffcms.org/api/api/news?lang=' . $this->lang);
         if ($news !== null && !Str::likeEmpty($news)) {
             App::$Cache->set('download.ffcms.api.news.' . $this->lang, $news, 3600 * 12);
         }
     }
     return $news;
 }