コード例 #1
0
ファイル: UserController.php プロジェクト: namcoder/Topshare
 public function complete_assignment($id)
 {
     $u = UserAssignment::find($id);
     $u->status = 5;
     $u->save();
     return redirect('admin/user-assignments')->with('ok', 'Completed');
 }
コード例 #2
0
 public function ajaxChangeStatus_UserAssignment()
 {
     $val = Request::input('val');
     $assignID = Request::input('assignID');
     $a = UserAssignment::find($assignID);
     $a->status = $val;
     $a->save();
 }
コード例 #3
0
 public function validate_user_assignment_link()
 {
     $link = Request::input('data');
     /// user report link
     $id = Request::input('user_assignment_id');
     $ua = UserAssignment::find($id);
     // user assignment
     /// used for (maybe) when user reached of max time to repost, then remove and return not exist to move
     if (!$ua) {
         return array('statusCode' => 500, 'content' => 'not_exist');
     }
     $current_allow = Setting::where('name', 'time_to_repost')->first()->value;
     /// reached of allow time to repost
     if ($ua->time_to_repost == 1) {
         //// remove current user assignment - return to available
         /// message to user this assignment is Canceled
         $ua->delete();
         return array('statusCode' => 500, 'content' => 'You have tried <strong>' . $current_allow . '</strong> times to repost but ' . $link . ' is not enough of quality. Your assignment is Canceled', 'overtime' => 'yes');
     }
     $ua->time_to_repost = $ua->time_to_repost - 1;
     $ua->save();
     /////*********************************
     $true_apply = UserAssignment::where('user_id', Auth::user()->id)->where('id', $id)->first();
     if (!$true_apply) {
         return array('statusCode' => 500, 'content' => 'not_exist');
     }
     $domain = strtolower($link);
     $domain = parse_url($domain, PHP_URL_HOST);
     $domain = preg_replace('/(?:https?:\\/\\/)?(?:www\\.)?(.*)\\/?$/i', '$1', $domain);
     $domain = preg_replace('/\\//i', '$1', $domain);
     /*
      *
      *	BEGIN TO VALIDATE AND MINUS TIME TO TRY AND PLUS MORE TIME IF FAILED
      *	If plus more time (minute_to_repost_time) , just get from Setting then plus with: created_at of this UA
      **/
     //// check link domain same with user blog domain
     if ($domain != Auth::user()->userblog->domain) {
         $this->plus_time_repost($ua);
         return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> is not match with your blog domain you have registered. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
     }
     /************************************************/
     /// ALL OK
     $assignment = Assignment::find($ua->assignment_id);
     $required_link = json_decode($assignment->img_link);
     $required_keyword = explode(',', $assignment->keyword);
     $wordcount = $assignment->minimum_wordcount;
     $curl = curl_init($link);
     curl_setopt($curl, CURLOPT_NOBODY, true);
     $result = curl_exec($curl);
     $headerStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($headerStatusCode == '404') {
         $this->plus_time_repost($ua);
         return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> does not exist. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
     } elseif ($headerStatusCode == '301') {
         return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> is redirected, please use direct link. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
     } elseif ($headerStatusCode == '200') {
         $result_complete_validate = $this->complete_validate_blog($required_link, $link, $required_keyword, $wordcount);
         if (isset($result_complete_validate['error']) && $result_complete_validate['error'] == 'not-enough') {
             /// not enough link
             $this->plus_time_repost($ua);
             $list_notfollow = '';
             if (count($result_complete_validate['list_notfollow'])) {
                 $list_notfollow .= '<ul>';
                 foreach ($result_complete_validate['list_notfollow'] as $ln) {
                     $list_notfollow .= ' <li><strong> ' . $ln . '</strong> rel="nofollow" is not allowed</li> ';
                 }
                 $list_notfollow .= '</ul>';
             }
             return array('statusCode' => 500, 'content' => 'Number of links required: <strong>' . $result_complete_validate['num'] . '</strong><br>' . $list_notfollow . '  . You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
         }
         if (isset($result_complete_validate['error']) && $result_complete_validate['error'] == 'not-enough-keyword') {
             $this->plus_time_repost($ua);
             $list_notOK_keyword = '';
             if (count($result_complete_validate['list_notOK_keyword'])) {
                 $list_notOK_keyword .= '<ul>';
                 foreach ($result_complete_validate['list_notOK_keyword'] as $ln) {
                     $list_notOK_keyword .= ' <li>Keyword: <strong> ' . $ln . '</strong>  not found</li> ';
                 }
                 $list_notOK_keyword .= '</ul>';
             }
             return array('statusCode' => 500, 'content' => 'Number of keyword required: <strong>' . $result_complete_validate['num'] . '</strong><br>' . $list_notOK_keyword . '. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
         }
         if (isset($result_complete_validate['error']) && $result_complete_validate['error'] == 'not-enough-wordcount') {
             $this->plus_time_repost($ua);
             return array('statusCode' => 500, 'content' => 'Number of words required: <strong>' . $result_complete_validate['num'] . '</strong>. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
         }
         /// ALl OKKKKKKKKKKKKKKK. Count user_assignment by assignment_id, if full with status 3, close this assignment
         UserAssignment::where('user_id', Auth::user()->id)->where('id', $id)->update(array('status' => 3, 'link' => $link, 'approved_at' => date('Y-m-d H:i:s', time())));
         /// 2 is Written
         $total = UserAssignment::where('assignment_id', $ua->assignment_id)->where('status', 3)->count();
         if ($total == $assignment->max_blogger) {
             $assignment->status = 0;
             $assignment->save();
         }
         return array('statusCode' => 200);
     } else {
         $this->plus_time_repost($ua);
         return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> is not valid. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
     }
 }