Exemple #1
0
 /**
  * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX.
  *
  * @return tempcode  The snippet
  */
 function run()
 {
     if (get_option('is_on_rating') == '0') {
         return do_lang_tempcode('INTERNAL_ERROR');
     }
     // Has there actually been any rating?
     if (strtoupper(ocp_srv('REQUEST_METHOD')) == 'POST' || ocp_srv('HTTP_REFERER') == '') {
         $rating = either_param_integer('rating', NULL);
     } else {
         $rating = post_param_integer('rating');
         // Will fail
     }
     $content_type = get_param('content_type');
     $type = get_param('type', '');
     $content_id = get_param('id');
     $content_url = get_param('content_url', '', true);
     $content_title = get_param('content_title', '', true);
     require_code('feedback');
     actualise_specific_rating($rating, get_page_name(), get_member(), $content_type, $type, $content_id, $content_url, $content_title);
     actualise_give_rating_points();
     $template = get_param('template', NULL);
     if ($template !== '') {
         if (is_null($template)) {
             $template = 'RATING_BOX';
         }
         return display_rating($content_url, $content_title, $content_type, $content_id, $template);
     }
     return do_lang_tempcode('THANKYOU_FOR_RATING_SHORT');
 }
Exemple #2
0
/**
 * Actually adds a rating to the specified resource.
 * It performs full checking of inputs, and will log a hackattack if the rating is not between 1 and 10.
 *
 * @param  boolean		Whether this resource allows rating (if not, this function does nothing - but it's nice to move out this common logic into the shared function)
 * @param  ID_TEXT		The type (download, etc) that this rating is for
 * @param  ID_TEXT		The ID of the type that this rating is for
 * @param  mixed			The URL to where the commenting will pass back to (to put into the comment topic header) (URLPATH or Tempcode)
 * @param  ?string		The title to where the commenting will pass back to (to put into the comment topic header) (NULL: don't know, but not first post so not important)
 */
function actualise_rating($allow_rating, $content_type, $content_id, $content_url, $content_title)
{
    if (get_option('is_on_rating') == '0' || !$allow_rating) {
        return;
    }
    global $RATINGS_STRUCTURE;
    $all_rating_criteria = array();
    if (array_key_exists($content_type, $RATINGS_STRUCTURE)) {
        $all_rating_criteria = array_keys($RATINGS_STRUCTURE[$content_type][1]);
    } else {
        $all_rating_criteria[] = '';
    }
    foreach ($all_rating_criteria as $type) {
        // Has there actually been any rating?
        $rating = post_param_integer('rating__' . $content_type . '__' . $type . '__' . $content_id, NULL);
        if (is_null($rating)) {
            return;
        }
        actualise_specific_rating($rating, get_page_name(), get_member(), $content_type, $type, $content_id, $content_url, $content_title);
    }
    actualise_give_rating_points();
    // Ok, so just thank 'em
    attach_message(do_lang_tempcode('THANKYOU_FOR_RATING'), 'inform');
}