Exemplo n.º 1
0
 /**
  * Used to rate photo
  */
 function rate_collection($id, $rating)
 {
     global $db, $json;
     if (!is_numeric($rating) || $rating <= 9) {
         $rating = 0;
     }
     if ($rating >= 10) {
         $rating = 10;
     }
     $c_rating = $this->current_rating($id);
     $voters = $c_rating['voters'];
     $new_rate = $c_rating['rating'];
     $rated_by = $c_rating['rated_by'];
     if (phpversion < '5.2.0') {
         $voters = $json->json_decode($voters, TRUE);
     } else {
         $voters = json_decode($voters, TRUE);
     }
     if (!empty($voters)) {
         $already_voted = array_key_exists(userid(), $voters);
     }
     if (!userid()) {
         e(lang("please_login_to_rate"));
     } elseif (userid() == $c_rating['userid'] && !config('own_collection_rating')) {
         e(lang("you_cannot_rate_own_collection"));
     } elseif (!empty($already_voted)) {
         e(lang("you_hv_already_rated_photo"));
     } elseif ($c_rating['allow_rating'] == 'no' || !config('collection_rating')) {
         e(lang("collection_rating_not_allowed"));
     } else {
         $voters[userid()] = array('rate' => $rating, 'time' => NOW());
         if (phpversion < '5.2.0') {
             $voters = $json->json_encode($voters);
         } else {
             $voters = json_encode($voters);
         }
         $t = $c_rating['rated_by'] * $c_rating['rating'];
         $rated_by = $c_rating['rated_by'] + 1;
         $new_rate = ($t + $rating) / $rated_by;
         $db->update(tbl('collections'), array('rating', 'rated_by', 'voters'), array("{$new_rate}", "{$rated_by}", "|no_mc|{$voters}"), " collection_id = " . $id . "");
         $userDetails = array("object_id" => $id, "type" => "collection", "time" => now(), "rating" => $rating, "userid" => userid(), "username" => username());
         /* Updating user details */
         update_user_voted($userDetails);
         e(lang("thnx_for_voting"), "m");
     }
     $return = array("rating" => $new_rate, "rated_by" => $rated_by, 'total' => 10, "id" => $id, "type" => "collection", "disable" => "disabled");
     return $return;
 }
Exemplo n.º 2
0
 /**
  * Function used to rate video
  */
 function rate_video($id, $rating)
 {
     global $db, $myquery, $userquery;
     if (!is_numeric($rating) || $rating <= 9) {
         $rating = 0;
     }
     if ($rating >= 10) {
         $rating = 10;
     }
     $rating_details = $this->get_video_rating($id);
     $voter_id = $rating_details['voter_ids'];
     $new_by = $rating_details['rated_by'];
     $newrate = $rating_details['rating'];
     if (phpversion < '5.2.0') {
         global $json;
     }
     $js = $json;
     $Oldvoters = explode('|', $voter_id);
     if (is_array($Oldvoters) && count($Oldvoters) > 2) {
         foreach ($Oldvoters as $voter) {
             if ($voter) {
                 $voters[$voter] = array("userid" => $voter, "time" => now(), "method" => 'old');
             }
         }
     } else {
         if (!empty($js)) {
             $voters = $js->json_decode($voter_id, TRUE);
         } else {
             $voters = json_decode($voter_id, TRUE);
         }
     }
     if (!empty($voters)) {
         $already_voted = array_key_exists(userid(), $voters);
     }
     if (!userid()) {
         e(lang("please_login_to_rate"));
     } elseif (userid() == $rating_details['userid'] && !config('own_video_rating')) {
         e(lang("you_cant_rate_own_video"));
     } elseif (!empty($already_voted) && !1) {
         e(lang("you_hv_already_rated_vdo"));
     } elseif (!config('video_rating') || $rating_details['allow_rating'] != 'yes') {
         e(lang("vid_rate_disabled"));
     } else {
         $voters[userid()] = array("userid" => userid(), "username" => username(), "time" => now(), "rating" => $rating);
         $total_voters = count($voters);
         if (!empty($js)) {
             $voters = $js->json_encode($voters);
         } else {
             $voters = json_encode($voters);
         }
         $t = $rating_details['rated_by'] * $rating_details['rating'];
         //$new_by = $rating_details['rated_by'] + 1;
         $new_by = $total_voters;
         $newrate = ($t + $rating) / $new_by;
         if ($newrate > 10) {
             $newrate = 10;
         }
         $newrate = round($newrate + 0.49, 0);
         $db->update(tbl($this->dbtbl['video']), array("rating", "rated_by", "voter_ids"), array($newrate, $new_by, "|no_mc|{$voters}"), " videoid='{$id}'");
         $userDetails = array("object_id" => $id, "type" => "video", "time" => now(), "rating" => $rating, "userid" => userid(), "username" => username());
         /* Updating user details */
         update_user_voted($userDetails);
         $like_array = array('userid' => userid(), 'type' => 'v', 'object_id' => $id);
         if ($rating > 1) {
             $myquery->add_like($like_array);
         } else {
             $myquery->add_dislike($like_array);
         }
         if (isSectionEnabled('feeds')) {
             //ADding feed
             global $cbfeeds;
             if ($rating > 1) {
                 $object = $this->get_content($id);
                 $user = $userquery->udetails;
                 $feed_array = array('userid' => userid(), 'user' => $user, 'object' => $object, 'object_id' => $id, 'object_type' => 'video', 'is_activity' => 'yes', 'action' => 'like_video');
                 $cbfeeds->add_feed($feed_array);
             } else {
                 $feed_array = array('userid' => userid(), 'object_id' => $id, 'object_type' => 'video', 'is_activity' => 'yes', 'action' => 'like_video');
                 $cbfeeds->delete_feed($feed_array);
             }
         }
         e(lang("thnx_for_voting"), "m");
     }
     $result = array('rating' => $newrate, 'ratings' => $new_by, 'total' => 10, 'id' => $id, 'type' => 'video', 'disable' => 'disabled');
     return $result;
     /*
      Following code is unused
      $niddle = "|";
      $niddle .= userid();
      $niddle .= "|";
      $flag = strstr($voter_id, $niddle);
     
      //checking if raings are allowed or not
      $vid_rating = config('video_rating');
     
      if(!userid())
      e(lang("please_login_to_rate"));
      elseif(userid()==$rating_details['userid'] && !config('own_video_rating'))
      e(lang("you_cant_rate_own_video"));
      elseif(!empty($flag))
      e(lang("you_hv_already_rated_vdo"));
      elseif(!config('video_rating') || $rating_details['allow_rating'] !='yes' )
      e(lang("vid_rate_disabled"));
      else
      {
      if(empty($voter_id))
      $voter_id .= "|";
      $voter_id .= userid();
      $voter_id .= "|";
      $t = $rating_details['rated_by'] * $rating_details['rating'];
      $new_by = $rating_details['rated_by'] + 1;
      $newrate = ($t + $rating) / $new_by;
     
      $db->update(tbl($this->dbtbl['video']),array("rating","rated_by","voter_ids"),array($newrate,$new_by,$voter_id)," videoid='$id'");
      e(lang("thnx_for_voting"),"m");
      }
     
      $result = array('rating'=>$newrate,'ratings'=>$new_by,'total'=>10,'id'=>$id,'type'=>'video','disable'=>'disabled');
      return $result;
     */
 }