Since: 0.1
Author: Jeroen De Dauw (jeroendedauw@gmail.com)
Example #1
0
 private function build_stats(Image $image)
 {
     $h_owner = html_escape($image->get_owner()->name);
     $h_ownerlink = "<a href='" . make_link("user/{$h_owner}") . "'>{$h_owner}</a>";
     $h_ip = html_escape($image->owner_ip);
     $h_date = autodate($image->posted);
     $h_filesize = to_shorthand_int($image->filesize);
     global $user;
     if ($user->can("view_ip")) {
         $h_ownerlink .= " ({$h_ip})";
     }
     $html = "\n\t\tId: {$image->id}\n\t\t<br>Posted: {$h_date} by {$h_ownerlink}\n\t\t<br>Size: {$image->width}x{$image->height}\n\t\t<br>Filesize: {$h_filesize}\n\t\t";
     if (!is_null($image->source)) {
         $h_source = html_escape($image->source);
         if (substr($image->source, 0, 7) != "http://" && substr($image->source, 0, 8) != "https://") {
             $h_source = "http://" . $h_source;
         }
         $html .= "<br>Source: <a href='{$h_source}'>link</a>";
     }
     if (class_exists("Ratings")) {
         if ($image->rating == null || $image->rating == "u") {
             $image->rating = "u";
         }
         $h_rating = Ratings::rating_to_human($image->rating);
         $html .= "<br>Rating: {$h_rating}";
     }
     return $html;
 }
Example #2
0
 public static function newInstance()
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #3
0
 /**
  * @param array $images
  * @param int $page_number
  * @param int $total_pages
  * @param bool $can_post
  */
 public function display_comment_list($images, $page_number, $total_pages, $can_post)
 {
     global $config, $page, $user;
     $page->disable_left();
     // parts for the whole page
     $prev = $page_number - 1;
     $next = $page_number + 1;
     $h_prev = $page_number <= 1 ? "Prev" : "<a href='" . make_link("comment/list/{$prev}") . "'>Prev</a>";
     $h_index = "<a href='" . make_link() . "'>Index</a>";
     $h_next = $page_number >= $total_pages ? "Next" : "<a href='" . make_link("comment/list/{$next}") . "'>Next</a>";
     $nav = "{$h_prev} | {$h_index} | {$h_next}";
     $page->set_title("Comments");
     $page->set_heading("Comments");
     $page->add_block(new Block("Navigation", $nav, "left"));
     $this->display_paginator($page, "comment/list", null, $page_number, $total_pages);
     // parts for each image
     $position = 10;
     $comment_captcha = $config->get_bool('comment_captcha');
     $comment_limit = $config->get_int("comment_list_count", 10);
     foreach ($images as $pair) {
         $image = $pair[0];
         $comments = $pair[1];
         $thumb_html = $this->build_thumb_html($image);
         $s = "&nbsp;&nbsp;&nbsp;";
         $un = $image->get_owner()->name;
         $t = "";
         foreach ($image->get_tag_array() as $tag) {
             $u_tag = url_escape($tag);
             $t .= "<a href='" . make_link("post/list/{$u_tag}/1") . "'>" . html_escape($tag) . "</a> ";
         }
         $p = autodate($image->posted);
         $r = class_exists("Ratings") ? "<b>Rating</b> " . Ratings::rating_to_human($image->rating) : "";
         $comment_html = "<b>Date</b> {$p} {$s} <b>User</b> {$un} {$s} {$r}<br><b>Tags</b> {$t}<p>&nbsp;";
         $comment_count = count($comments);
         if ($comment_limit > 0 && $comment_count > $comment_limit) {
             //$hidden = $comment_count - $comment_limit;
             $comment_html .= "<p>showing {$comment_limit} of {$comment_count} comments</p>";
             $comments = array_slice($comments, -$comment_limit);
         }
         foreach ($comments as $comment) {
             $comment_html .= $this->comment_to_html($comment);
         }
         if ($can_post) {
             if (!$user->is_anonymous()) {
                 $comment_html .= $this->build_postbox($image->id);
             } else {
                 if (!$comment_captcha) {
                     $comment_html .= $this->build_postbox($image->id);
                 } else {
                     $comment_html .= "<a href='" . make_link("post/view/" . $image->id) . "'>Add Comment</a>";
                 }
             }
         }
         $html = "\n\t\t\t\t<table><tr>\n\t\t\t\t\t<td style='width: 220px;'>{$thumb_html}</td>\n\t\t\t\t\t<td style='text-align: left;'>{$comment_html}</td>\n\t\t\t\t</tr></table>\n\t\t\t";
         $page->add_block(new Block("&nbsp;", $html, "main", $position++));
     }
 }
Example #4
0
 public static function init()
 {
     global $context, $modSettings, $txt;
     $modSettings['ratings'] = !empty($modSettings['raw_ratings']) ? @unserialize($modSettings['raw_ratings']) : array();
     loadLanguage('Ratings');
     foreach ($modSettings['ratings'] as &$rating) {
         $rating['text'] = sprintf(html_entity_decode($rating['format']), !empty($rating['localized']) && isset($txt[$rating['localized']]) ? $txt[$rating['localized']] : $rating['label']);
     }
     self::$is_valid = isset($modSettings['ratings']) && count($modSettings['ratings']) > 0 ? true : false;
     $context['can_see_like'] = self::$perm_can_see = self::$is_valid ? allowedTo('like_see') : false;
     $context['can_give_like'] = self::$perm_can_give = self::$is_valid ? allowedTo('like_give') : false;
     self::$show_repair_link = !empty($modSettings['rating_show_repair']) ? true : false;
     self::$rate_bar = '<a onclick="ratingWidgetInvoke($(this));return(false);" rel="nofollow" href="!#" class="widgetanchor">' . $txt['rate_this'] . '</a>';
 }
Example #5
0
 public function onPostListBuilding($event)
 {
     global $config, $page, $user;
     $fid = $config->get_int("featured_id");
     if ($fid > 0) {
         $image = Image::by_id($fid);
         if (!is_null($image)) {
             if (class_exists("Ratings")) {
                 if (strpos(Ratings::get_user_privs($user), $image->rating) === FALSE) {
                     return;
                 }
             }
             $this->theme->display_featured($page, $image);
         }
     }
 }
Example #6
0
 public function testVolumeCheckFailed()
 {
     $this->ratings = new Ratings($this->destination, $this->logger, $this->progress, 'volume');
     $this->progress->expects($this->once())->method('start')->with(1);
     $this->progress->expects($this->once())->method('advance');
     $this->progress->expects($this->once())->method('finish');
     $this->destination->expects($this->once())->method('getAdapter')->willReturn($this->adapter);
     $this->adapter->expects($this->exactly(2))->method('getSelect')->willReturn($this->select);
     $this->select->expects($this->at(0))->method('from')->with('rating_store', ['rating_id'])->will($this->returnSelf());
     $this->select->expects($this->at(1))->method('where')->with('store_id > 0')->will($this->returnSelf());
     $this->adapter->expects($this->at(1))->method('loadDataFromSelect')->with($this->select)->willReturn([['rating_id' => 1]]);
     $this->adapter->expects($this->at(3))->method('loadDataFromSelect')->with($this->select)->willReturn([['rating_id' => 2]]);
     $this->select->expects($this->at(2))->method('from')->with('rating', ['rating_id'])->will($this->returnSelf());
     $this->select->expects($this->at(3))->method('where')->with('is_active = ?', 1)->will($this->returnSelf());
     $this->logger->expects($this->once())->method('warning')->with('Mismatch of entities in the documents: rating, rating_store');
     $this->assertFalse($this->ratings->perform());
 }
Example #7
0
 public function onPostListBuilding(PostListBuildingEvent $event)
 {
     global $config, $database, $page, $user;
     $fid = $config->get_int("featured_id");
     if ($fid > 0) {
         $image = $database->cache->get("featured_image_object:{$fid}");
         if ($image === false) {
             $image = Image::by_id($fid);
             if ($image) {
                 // make sure the object is fully populated before saving
                 $image->get_tag_array();
             }
             $database->cache->set("featured_image_object:{$fid}", $image, 600);
         }
         if (!is_null($image)) {
             if (class_exists("Ratings")) {
                 if (strpos(Ratings::get_user_privs($user), $image->rating) === FALSE) {
                     return;
                 }
             }
             $this->theme->display_featured($page, $image);
         }
     }
 }
Example #8
0
 private function build_page($current_page)
 {
     global $page;
     global $config;
     global $database;
     if (class_exists("Ratings")) {
         global $user;
         $user_ratings = Ratings::get_user_privs($user);
     }
     if (is_null($current_page) || $current_page <= 0) {
         $current_page = 1;
     }
     $threads_per_page = 10;
     $start = $threads_per_page * ($current_page - 1);
     $get_threads = "\n\t\t\tSELECT image_id,MAX(posted) AS latest\n\t\t\tFROM comments\n\t\t\tGROUP BY image_id\n\t\t\tORDER BY latest DESC\n\t\t\tLIMIT ? OFFSET ?\n\t\t\t";
     $result = $database->Execute($get_threads, array($threads_per_page, $start));
     $total_pages = (int) ($database->db->GetOne("SELECT COUNT(c1) FROM (SELECT COUNT(image_id) AS c1 FROM comments GROUP BY image_id) AS s1") / 10);
     $images = array();
     while (!$result->EOF) {
         $image = Image::by_id($result->fields["image_id"]);
         $comments = $this->get_comments($image->id);
         if (class_exists("Ratings")) {
             if (strpos($user_ratings, $image->rating) === FALSE) {
                 $image = null;
                 // this is "clever", I may live to regret it
             }
         }
         if (!is_null($image)) {
             $images[] = array($image, $comments);
         }
         $result->MoveNext();
     }
     $this->theme->display_comment_list($images, $current_page, $total_pages, $this->can_comment());
 }
Example #9
0
<?php

use Project\Classes\DB\DB;
include '../../../autoloader.php';
require_once '../../Model/Ratings.php';
require_once '../../database.php';
// Get FilmIDs
$rating_id = $_POST['rating_id'];
// Delete the product from the database
$deleteRatings = new Ratings();
$deleteRatings->deleteMovie($rating_id);
//header('location: ../View/Ratings_Index.php');     // Redirect to display the Rating List
header('location: /admin/rating');
Example #10
0
<?php

error_reporting(E_ALL);
// get all required data
require_once 'settings/application.php';
// get student ratings
$ratings = new Ratings();
$ratingsAll = $ratings->select(array('students_ratings' => true));
// get info about student
$studentId = 0;
$studentInfo = null;
if (!empty($_GET['userId'])) {
    $studentId = (int) $_GET['userId'];
} elseif (!empty($ratingsAll)) {
    reset($ratingsAll);
    $studentId = key($ratingsAll);
}
if (!empty($ratingsAll[$studentId])) {
    $studentInfo = $ratingsAll[$studentId];
}
// format date
$studentInfo = Api::formatDate($studentInfo);
// get specialization
$users = new Users();
$specialization = $users->getSpecialization($studentId);
// get student ratings grouped by season
$seasonRatings = array();
foreach ($studentInfo as $value) {
    $seasonRatings[$value['date_formated']][] = $value['lesson_title'] . ' ' . '<span class="subject_course">' . $value['course'] . '</span>' . ' ' . '<span class="subject_rating">' . $value['rating'] . '</span>';
}
// view
Example #11
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.1
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     $parameters['page'] = $parameters['page'] === false ? $GLOBALS['wgTitle'] : Title::newFromText($parameters['page']);
     return htmlspecialchars(Ratings::getRatingSummaryMessage($parameters['page'], $parameters['tag']));
 }
Example #12
0
				<p class="text-center title-text">Кратко описание</p>
				<p class="text-center"><?php 
echo $landmarkInfo->review;
?>
</p>
				<p class="text-center title-text">Дай своя глас</p>
				<?php 
require '../classes/ratings.php';
$isRated = (new Ratings())->isRated((int) $_GET['landmark_id'], $_SESSION['id']);
?>
				<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    ?>
  
			        <?php 
    $rating = new Ratings();
    ?>
			        	<?php 
    if ($isRated == false) {
        ?>
			            	<?php 
        $isRated = $rating->setRatingLandmark($_POST['rateSelector'], $_GET['landmark_id'], $_SESSION['id']);
        ?>
			          	<?php 
    }
    ?>
			          	<?php 
    if ($isRated == true) {
        ?>
			           		<?php 
        $rating->updateRatingLandmark($_POST['rateSelector'], (int) $_GET['landmark_id'], (int) $_SESSION['id']);
Example #13
0
Route::get('comments/{id}/edit', ['as' => 'comments.edit', 'uses' => function ($id) {
    return Comments::edit($id);
}]);
Route::put('comments/{id}/update', ['as' => 'comments.update', 'middleware' => 'csrf', 'uses' => function ($id) {
    return Comments::update($id);
}]);
Route::delete('comments/{id}/delete', ['as' => 'comments.delete', 'middleware' => 'csrf', 'uses' => function ($id) {
    return Comments::delete($id);
}]);
/*
 * Ratings
 */
Route::post('ratings/store', ['as' => 'ratings.store', 'middleware' => 'csrf', 'uses' => function () {
    $foreignType = Input::get('foreigntype');
    $foreignId = Input::get('foreignid');
    return Ratings::store($foreignType, $foreignId);
}]);
/*
 * Captcha
 */
Route::get('captcha', ['as' => 'captcha', 'uses' => function () {
    Captcha::make();
    $response = Response::make('', 200);
    $response->header('Content-Type', 'image/jpg');
    return $response;
}]);
/*
 * Installation
 */
Route::get('install', 'InstallController@index');
Route::post('install', 'InstallController@index');
Example #14
0
 public function onSearchTermParse(SearchTermParseEvent $event)
 {
     global $user;
     $matches = array();
     if (is_null($event->term) && $this->no_rating_query($event->context)) {
         $set = Ratings::privs_to_sql(Ratings::get_user_privs($user));
         $event->add_querylet(new Querylet("rating IN ({$set})"));
     }
     if (preg_match("/^rating[=|:](?:([sqeu]+)|(safe|questionable|explicit|unknown))\$/D", strtolower($event->term), $matches)) {
         $ratings = $matches[1] ? $matches[1] : $matches[2][0];
         $ratings = array_intersect(str_split($ratings), str_split(Ratings::get_user_privs($user)));
         $set = "'" . join("', '", $ratings) . "'";
         $event->add_querylet(new Querylet("rating IN ({$set})"));
     }
 }
	/**
	 * Loads the needed JavaScript.
	 * Takes care of non-RL compatibility.
	 * 
	 * @since 0.1
	 * 
	 * @param array $parameters
	 */
	protected function loadJs( array $parameters ) {
		static $loadedJs = false;
		
		if ( $loadedJs ) {
			return;
		}
		
		$loadedJs = true;
		
		$this->addJSWikiData( $parameters );
		
		// For backward compatibility with MW < 1.17.
		if ( is_callable( array( $this->parser->getOutput(), 'addModules' ) ) ) {
			$this->parser->getOutput()->addModules( 'ext.ratings.stars' );
		}
		else {
			global $egRatingsScriptPath, $wgStylePath, $wgStyleVersion;
			
			$this->addJSLocalisation();

			$this->parser->getOutput()->addHeadItem(
				Html::linkedScript( "$wgStylePath/common/jquery.min.js?$wgStyleVersion" ),
				'jQuery'
			);
			
			Ratings::loadJs( $this->parser );
			
			$this->parser->getOutput()->addHeadItem(
				Html::linkedScript( $egRatingsScriptPath . '/starrating/star-rating/jquery.rating.js' )
				. Html::linkedStyle( $egRatingsScriptPath . '/starrating/star-rating/jquery.rating.css' ),
				'ext.ratings.stars.jquery'
			);			
			
			$this->parser->getOutput()->addHeadItem(
				Html::linkedScript( $egRatingsScriptPath . '/starrating/ext.ratings.stars.js' ),
				'ext.ratings.stars'
			);
		}		
	}	
Example #16
0
 /**
  * @param int $current_page
  */
 private function build_page($current_page)
 {
     global $database, $user;
     $where = SPEED_HAX ? "WHERE posted > now() - interval '24 hours'" : "";
     $total_pages = $database->cache->get("comment_pages");
     if (empty($total_pages)) {
         $total_pages = (int) ($database->get_one("\n\t\t\t\tSELECT COUNT(c1)\n\t\t\t\tFROM (SELECT COUNT(image_id) AS c1 FROM comments {$where} GROUP BY image_id) AS s1\n\t\t\t") / 10);
         $database->cache->set("comment_pages", $total_pages, 600);
     }
     $total_pages = max($total_pages, 1);
     $current_page = clamp($current_page, 1, $total_pages);
     $threads_per_page = 10;
     $start = $threads_per_page * ($current_page - 1);
     $result = $database->Execute("\n\t\t\tSELECT image_id,MAX(posted) AS latest\n\t\t\tFROM comments\n\t\t\t{$where}\n\t\t\tGROUP BY image_id\n\t\t\tORDER BY latest DESC\n\t\t\tLIMIT :limit OFFSET :offset\n\t\t", array("limit" => $threads_per_page, "offset" => $start));
     $user_ratings = ext_is_live("Ratings") ? Ratings::get_user_privs($user) : "";
     $images = array();
     while ($row = $result->fetch()) {
         $image = Image::by_id($row["image_id"]);
         if (ext_is_live("Ratings") && !is_null($image) && strpos($user_ratings, $image->rating) === FALSE) {
             $image = null;
             // this is "clever", I may live to regret it
         }
         if (!is_null($image)) {
             $comments = $this->get_comments($image->id);
             $images[] = array($image, $comments);
         }
     }
     $this->theme->display_comment_list($images, $current_page, $total_pages, $user->can("create_comment"));
 }
Example #17
0
function prepareDisplayContext($reset = false)
{
    global $txt, $modSettings, $options, $user_info, $output;
    global $memberContext, $context, $messages_request;
    static $counter = null;
    static $seqnr = 0;
    // If the query returned false, bail.
    if ($messages_request == false) {
        return false;
    }
    // Remember which message this is.  (ie. reply #83)
    if ($counter === null || $reset) {
        $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
    }
    // Start from the beginning...
    if ($reset) {
        return @mysql_data_seek($messages_request, 0);
    }
    // Attempt to get the next message.
    $message = mysql_fetch_assoc($messages_request);
    if (!$message) {
        mysql_free_result($messages_request);
        return false;
    }
    // If you're a lazy bum, you probably didn't give a subject...
    $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
    // Are you allowed to remove at least a single reply?
    $context['can_remove_post'] |= $context['can_delete_own'] && (empty($modSettings['edit_disable_time']) || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()) && $message['id_member'] == $user_info['id'];
    // If it couldn't load, or the user was a guest.... someday may be done with a guest table.
    if (!loadMemberContext($message['id_member'], true)) {
        // Notice this information isn't used anywhere else....
        $memberContext[$message['id_member']]['name'] = $message['poster_name'];
        $memberContext[$message['id_member']]['id'] = 0;
        $memberContext[$message['id_member']]['group'] = $txt['guest_title'];
        $memberContext[$message['id_member']]['link'] = $message['poster_name'];
        $memberContext[$message['id_member']]['email'] = $message['poster_email'];
        $memberContext[$message['id_member']]['show_email'] = showEmailAddress(true, 0);
        $memberContext[$message['id_member']]['is_guest'] = true;
        $memberContext[$message['id_member']]['is_banned_from_topic'] = $memberContext[$message['id_member']]['can_see_warning'] = false;
    } else {
        $memberContext[$message['id_member']]['can_view_profile'] = $context['can_profile_view_any'] || $message['id_member'] == $user_info['id'] && $context['can_profile_view_own'];
        $memberContext[$message['id_member']]['is_topic_starter'] = $message['id_member'] == $context['topic_starter_id'];
        $memberContext[$message['id_member']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member']]['warning_status'] && ($context['user']['can_mod'] || !$user_info['is_guest'] && !empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member'] == $user_info['id']));
        $memberContext[$message['id_member']]['is_banned_from_topic'] = !empty($context['topic_banned_members']) ? in_array($message['id_member'], $context['topic_banned_members']) : false;
    }
    $memberContext[$message['id_member']]['ip'] = $message['poster_ip'];
    // Do the censor thang.
    censorText($message['subject']);
    // create a cached (= parsed) version of the post on the fly
    // but only if it's not older than the cutoff time.
    // and do not cache more than PCACHE_UPDATE_PER_VIEW posts per thread view to reduce load spikes
    $dateline = max($message['modified_time'], $message['poster_time']);
    if ($context['pcache_update_counter'] < PCACHE_UPDATE_PER_VIEW && $context['time_cutoff_ref'] - $dateline < $modSettings['post_cache_cutoff'] * 86400) {
        if (empty($message['cached_body'])) {
            $context['pcache_update_counter']++;
            $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], '');
            // don't cache bbc when we pre-parse the post anyway...
            smf_db_insert('replace', '{db_prefix}messages_cache', array('id_msg' => 'int', 'body' => 'string', 'style' => 'string', 'lang' => 'string', 'updated' => 'int'), array($message['id_msg'], $message['body'], $user_info['smiley_set_id'], $user_info['language_id'], $dateline), array('id_msg', 'body', 'style', 'lang', 'updated'));
            parse_bbc_stage2($message['body'], $message['id_msg']);
        } else {
            $message['body'] =& $message['cached_body'];
            parse_bbc_stage2($message['body'], $message['id_msg']);
        }
    } else {
        $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg'] . '|' . $message['modified_time']);
        parse_bbc_stage2($message['body'], $message['id_msg']);
    }
    censorText($message['body']);
    // Compose the memory eat- I mean message array.
    //$t_href = URL::topic($topic, $message['subject'], 0, false, '.msg' . $message['id_msg'] . '#msg'.$message['id_msg']);
    $output = array('attachment' => loadAttachmentContext($message['id_msg']), 'id' => $message['id_msg'], 'permahref' => URL::parse('?msg=' . $message['id_msg'] . (isset($_REQUEST['perma']) ? '' : ';perma')), 'member' => &$memberContext[$message['id_member']], 'icon' => $message['icon'], 'icon_url' => getPostIcon($message['icon']), 'subject' => $message['subject'], 'time' => timeformat($message['poster_time']), 'timestamp' => $message['poster_time'], 'counter' => $counter, 'permalink' => isset($_REQUEST['perma']) ? $txt['view_in_thread'] : ' #' . ($counter + 1), 'modified' => array('time' => timeformat($message['modified_time']), 'name' => $message['modified_name']), 'body' => &$message['body'], 'new' => empty($message['is_read']), 'approved' => $message['approved'], 'first_new' => isset($context['start_from']) && $context['start_from'] == $counter, 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($message['id_member'], $context['user']['ignoreusers']), 'can_approve' => !$message['approved'] && $context['can_approve'], 'can_unapprove' => $message['approved'] && $context['can_unapprove'], 'can_modify' => (!$message['locked'] || $context['can_moderate_board']) && ((!$context['is_locked'] || $context['can_moderate_board']) && ($context['can_modify_any'] || $context['can_modify_replies'] && $context['user']['started'] || $context['can_modify_own'] && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || !$message['approved'] || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time()))), 'can_remove' => (!$message['locked'] || $context['can_moderate_board']) && ($context['can_delete_any'] || $context['can_delete_replies'] && $context['user']['started'] || $context['can_delete_own'] && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time())), 'can_see_ip' => $context['can_moderate_forum'] || $message['id_member'] == $user_info['id'] && !empty($user_info['id']), 'likes_count' => $message['likes_count'], 'like_status' => $message['like_status'], 'liked' => $message['liked'], 'like_updated' => $message['like_updated'], 'id_member' => $message['id_member'], 'postbit_callback' => $message['approved'] ? $message['id_msg'] == $context['first_message'] ? $context['postbit_callbacks']['firstpost'] : $context['postbit_callbacks']['post'] : 'template_postbit_comment', 'postbit_template_class' => $message['approved'] ? $message['id_msg'] == $context['first_message'] ? $context['postbit_template_class']['firstpost'] : $context['postbit_template_class']['post'] : 'c', 'mq_marked' => in_array($message['id_msg'], $context['multiquote_posts']), 'header_class' => $context['can_moderate_member'] && ($memberContext[$message['id_member']]['is_banned_from_topic'] || $memberContext[$message['id_member']]['can_see_warning']) ? ' watched' : '');
    if ($context['can_see_like']) {
        Ratings::addContent($output, $context['can_give_like'], $context['time_cutoff_ref']);
    } else {
        $output['likes_count'] = 0;
    }
    // Is this user the message author?
    $output['is_message_author'] = $message['id_member'] == $user_info['id'];
    $counter += empty($options['view_newest_first']) ? 1 : -1;
    // hooks can populate these fields with additional content
    $output['template_hook'] = array('before_sig' => '', 'after_sig' => '', 'postbit_below' => '', 'poster_details' => '');
    HookAPI::callHook('display_postbit', array(&$output));
    if (isset($output['member']['can_see_warning']) && !empty($output['member']['can_see_warning'])) {
        $output['member']['warning_status_desc'] = isset($output['member']['warning_status']) ? $txt['user_warn_' . $output['member']['warning_status']] : '';
        $output['member']['warning_status_desc1'] = isset($output['member']['warning_status']) ? $txt['warn_' . $output['member']['warning_status']] : '';
    }
    $output['member']['allow_show_email'] = $output['member']['is_guest'] ? !empty($output['member']['email']) && in_array($output['member']['show_email'], array('yes', 'yes_permission_override', 'no_through_forum')) : false;
    //$context['current_message'] = &$output;
    if ($output['can_remove']) {
        $context['removableMessageIDs'][] = $output['id'];
    }
    //return $output;
}
Example #18
0
function update_rating($item, $user, $rating)
{
    return Ratings::newInstance()->updateRatingsData($item, $user, $rating);
}
Example #19
0
function HandleLikeRequest()
{
    global $sourcedir, $modSettings, $txt;
    $mid = isset($_REQUEST['m']) ? (int) $_REQUEST['m'] : 0;
    if ($mid > 0 && !empty($modSettings['karmaMode'])) {
        require_once $sourcedir . '/lib/Subs-Ratings.php';
        Ratings::rateIt($mid);
    } else {
        AjaxErrorMsg($txt['post_ratings_disabled']);
    }
}
Example #20
0
     $voted = 1;
 }
 //var_dump($id_sent);
 if (!$voted) {
     //if the user hasn't yet voted, then vote normally...
     if ($vote_sent >= 1 && $vote_sent <= $units) {
         $updateRate = new Ratings();
         $result = $updateRate->updateRating($added, $sum, $insertIP, $id_sent);
         if ($result) {
             setcookie("rating_" . $id_sent, 1, time() + 2592000, '/');
         }
     }
 }
 //end for the "if(!$voted)"
 // these are new queries to get the new values!
 $disAll = new Ratings();
 $numbers = $disAll->displayValues($id_sent);
 //$numbers = mysql_fetch_assoc($newtotals);
 $count = $numbers['total_votes'];
 //how many votes total
 $current_rating = $numbers['total_value'];
 //total number of rating added together and stored
 $tense = $count == 1 ? "vote" : "votes";
 //plural form votes/vote
 // $new_back is what gets 'drawn' on your page after a successful 'AJAX/Javascript' vote
 if ($voted) {
     $sum = $current_rating;
     //storing total_value from database to new varibale
     $added = $count;
     //storing total_votes from database to new varibale
 }
Example #21
0
function removeMessage($message, $decreasePostCount = true)
{
    global $board, $sourcedir, $backend_subdir, $modSettings, $user_info;
    if (empty($message) || !is_numeric($message)) {
        return false;
    }
    $request = smf_db_query('
		SELECT
			m.id_member, m.icon, m.poster_time, m.subject,' . (empty($modSettings['search_custom_index_config']) ? '' : ' m.body,') . '
			m.approved, t.id_topic, t.id_first_msg, t.id_last_msg, t.num_replies, t.id_board,
			t.id_member_started AS id_member_poster,
			b.count_posts
		FROM {db_prefix}messages AS m
			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
		WHERE m.id_msg = {int:id_msg}
		LIMIT 1', array('id_msg' => $message));
    if (mysql_num_rows($request) == 0) {
        return false;
    }
    $row = mysql_fetch_assoc($request);
    mysql_free_result($request);
    if (empty($board) || $row['id_board'] != $board) {
        $delete_any = boardsAllowedTo('delete_any');
        if (!in_array(0, $delete_any) && !in_array($row['id_board'], $delete_any)) {
            $delete_own = boardsAllowedTo('delete_own');
            $delete_own = in_array(0, $delete_own) || in_array($row['id_board'], $delete_own);
            $delete_replies = boardsAllowedTo('delete_replies');
            $delete_replies = in_array(0, $delete_replies) || in_array($row['id_board'], $delete_replies);
            if ($row['id_member'] == $user_info['id']) {
                if (!$delete_own) {
                    if ($row['id_member_poster'] == $user_info['id']) {
                        if (!$delete_replies) {
                            fatal_lang_error('cannot_delete_replies', 'permission');
                        }
                    } else {
                        fatal_lang_error('cannot_delete_own', 'permission');
                    }
                } elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
                    fatal_lang_error('modify_post_time_passed', false);
                }
            } elseif ($row['id_member_poster'] == $user_info['id']) {
                if (!$delete_replies) {
                    fatal_lang_error('cannot_delete_replies', 'permission');
                }
            } else {
                fatal_lang_error('cannot_delete_any', 'permission');
            }
        }
        // Can't delete an unapproved message, if you can't see it!
        if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any))) {
            $approve_posts = boardsAllowedTo('approve_posts');
            if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) {
                return false;
            }
        }
    } else {
        // Check permissions to delete this message.
        if ($row['id_member'] == $user_info['id']) {
            if (!allowedTo('delete_own')) {
                if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
                    isAllowedTo('delete_replies');
                } elseif (!allowedTo('delete_any')) {
                    isAllowedTo('delete_own');
                }
            } elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
                fatal_lang_error('modify_post_time_passed', false);
            }
        } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
            isAllowedTo('delete_replies');
        } else {
            isAllowedTo('delete_any');
        }
        if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) {
            isAllowedTo('approve_posts');
        }
    }
    // Close any moderation reports for this message.
    smf_db_query('
		UPDATE {db_prefix}log_reported
		SET closed = {int:is_closed}
		WHERE id_msg = {int:id_msg}', array('is_closed' => 1, 'id_msg' => $message));
    if (smf_db_affected_rows() != 0) {
        require_once $sourcedir . '/ModerationCenter.php';
        updateSettings(array('last_mod_report_action' => time()));
        recountOpenReports();
    }
    // Delete the *whole* topic, but only if the topic consists of one message.
    if ($row['id_first_msg'] == $message) {
        if (empty($board) || $row['id_board'] != $board) {
            $remove_any = boardsAllowedTo('remove_any');
            $remove_any = in_array(0, $remove_any) || in_array($row['id_board'], $remove_any);
            if (!$remove_any) {
                $remove_own = boardsAllowedTo('remove_own');
                $remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own);
            }
            if ($row['id_member'] != $user_info['id'] && !$remove_any) {
                fatal_lang_error('cannot_remove_any', 'permission');
            } elseif (!$remove_any && !$remove_own) {
                fatal_lang_error('cannot_remove_own', 'permission');
            }
        } else {
            // Check permissions to delete a whole topic.
            if ($row['id_member'] != $user_info['id']) {
                isAllowedTo('remove_any');
            } elseif (!allowedTo('remove_any')) {
                isAllowedTo('remove_own');
            }
        }
        // ...if there is only one post.
        if (!empty($row['num_replies'])) {
            fatal_lang_error('delFirstPost', false);
        }
        removeTopics($row['id_topic']);
        return true;
    }
    // Deleting a recycled message can not lower anyone's post count.
    if ($row['icon'] == 'recycled') {
        $decreasePostCount = false;
    }
    // This is the last post, update the last post on the board.
    if ($row['id_last_msg'] == $message) {
        // Find the last message, set it, and decrease the post count.
        $request = smf_db_query('
			SELECT id_msg, id_member
			FROM {db_prefix}messages
			WHERE id_topic = {int:id_topic}
				AND id_msg != {int:id_msg}
			ORDER BY ' . ($modSettings['postmod_active'] ? 'approved DESC, ' : '') . 'id_msg DESC
			LIMIT 1', array('id_topic' => $row['id_topic'], 'id_msg' => $message));
        $row2 = mysql_fetch_assoc($request);
        mysql_free_result($request);
        smf_db_query('
			UPDATE {db_prefix}topics
			SET
				id_last_msg = {int:id_last_msg},
				id_member_updated = {int:id_member_updated}' . (!$modSettings['postmod_active'] || $row['approved'] ? ',
				num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : ',
				unapproved_posts = CASE WHEN unapproved_posts = {int:no_unapproved} THEN 0 ELSE unapproved_posts - 1 END') . '
			WHERE id_topic = {int:id_topic}', array('id_last_msg' => $row2['id_msg'], 'id_member_updated' => $row2['id_member'], 'no_replies' => 0, 'no_unapproved' => 0, 'id_topic' => $row['id_topic']));
    } else {
        smf_db_query('
			UPDATE {db_prefix}topics
			SET ' . ($row['approved'] ? '
				num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : '
				unapproved_posts = CASE WHEN unapproved_posts = {int:no_unapproved} THEN 0 ELSE unapproved_posts - 1 END') . '
			WHERE id_topic = {int:id_topic}', array('no_replies' => 0, 'no_unapproved' => 0, 'id_topic' => $row['id_topic']));
    }
    // Default recycle to false.
    $recycle = false;
    // If recycle topics has been set, make a copy of this message in the recycle board.
    // Make sure we're not recycling messages that are already on the recycle board.
    if (!empty($modSettings['recycle_enable']) && $row['id_board'] != $modSettings['recycle_board'] && $row['icon'] != 'recycled') {
        // Check if the recycle board exists and if so get the read status.
        $request = smf_db_query('
			SELECT (IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_seen, id_last_msg
			FROM {db_prefix}boards AS b
				LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})
			WHERE b.id_board = {int:recycle_board}', array('current_member' => $user_info['id'], 'recycle_board' => $modSettings['recycle_board']));
        if (mysql_num_rows($request) == 0) {
            fatal_lang_error('recycle_no_valid_board');
        }
        list($isRead, $last_board_msg) = mysql_fetch_row($request);
        mysql_free_result($request);
        // Is there an existing topic in the recycle board to group this post with?
        $request = smf_db_query('
			SELECT id_topic, id_first_msg, id_last_msg
			FROM {db_prefix}topics
			WHERE id_previous_topic = {int:id_previous_topic}
				AND id_board = {int:recycle_board}', array('id_previous_topic' => $row['id_topic'], 'recycle_board' => $modSettings['recycle_board']));
        list($id_recycle_topic, $first_topic_msg, $last_topic_msg) = mysql_fetch_row($request);
        mysql_free_result($request);
        // Insert a new topic in the recycle board if $id_recycle_topic is empty.
        if (empty($id_recycle_topic)) {
            smf_db_insert('', '{db_prefix}topics', array('id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int', 'id_last_msg' => 'int', 'unapproved_posts' => 'int', 'approved' => 'int', 'id_previous_topic' => 'int'), array($modSettings['recycle_board'], $row['id_member'], $row['id_member'], $message, $message, 0, 1, $row['id_topic']), array('id_topic'));
        }
        // Capture the ID of the new topic...
        $topicID = empty($id_recycle_topic) ? smf_db_insert_id('{db_prefix}topics', 'id_topic') : $id_recycle_topic;
        // If the topic creation went successful, move the message.
        if ($topicID > 0) {
            smf_db_query('
				UPDATE {db_prefix}messages
				SET
					id_topic = {int:id_topic},
					id_board = {int:recycle_board},
					icon = {string:recycled},
					approved = {int:is_approved}
				WHERE id_msg = {int:id_msg}', array('id_topic' => $topicID, 'recycle_board' => $modSettings['recycle_board'], 'id_msg' => $message, 'recycled' => 'recycled', 'is_approved' => 1));
            // Take any reported posts with us...
            smf_db_query('
				UPDATE {db_prefix}log_reported
				SET
					id_topic = {int:id_topic},
					id_board = {int:recycle_board}
				WHERE id_msg = {int:id_msg}', array('id_topic' => $topicID, 'recycle_board' => $modSettings['recycle_board'], 'id_msg' => $message));
            // Mark recycled topic as read.
            if (!$user_info['is_guest']) {
                smf_db_insert('replace', '{db_prefix}log_topics', array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), array($topicID, $user_info['id'], $modSettings['maxMsgID']), array('id_topic', 'id_member'));
            }
            // Mark recycle board as seen, if it was marked as seen before.
            if (!empty($isRead) && !$user_info['is_guest']) {
                smf_db_insert('replace', '{db_prefix}log_boards', array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']), array('id_board', 'id_member'));
            }
            // Add one topic and post to the recycle bin board.
            smf_db_query('
				UPDATE {db_prefix}boards
				SET
					num_topics = num_topics + {int:num_topics_inc},
					num_posts = num_posts + 1' . ($message > $last_board_msg ? ', id_last_msg = {int:id_merged_msg}' : '') . '
				WHERE id_board = {int:recycle_board}', array('num_topics_inc' => empty($id_recycle_topic) ? 1 : 0, 'recycle_board' => $modSettings['recycle_board'], 'id_merged_msg' => $message));
            // Lets increase the num_replies, and the first/last message ID as appropriate.
            if (!empty($id_recycle_topic)) {
                smf_db_query('
					UPDATE {db_prefix}topics
					SET num_replies = num_replies + 1' . ($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') . ($message < $first_topic_msg ? ', id_first_msg = {int:id_merged_msg}' : '') . '
					WHERE id_topic = {int:id_recycle_topic}', array('id_recycle_topic' => $id_recycle_topic, 'id_merged_msg' => $message));
            }
            // Make sure this message isn't getting deleted later on.
            $recycle = true;
            // Make sure we update the search subject index.
            updateStats('subject', $topicID, $row['subject']);
        }
        // If it wasn't approved don't keep it in the queue.
        if (!$row['approved']) {
            smf_db_query('
				DELETE FROM {db_prefix}approval_queue
				WHERE id_msg = {int:id_msg}
					AND id_attach = {int:id_attach}', array('id_msg' => $message, 'id_attach' => 0));
        }
    }
    smf_db_query('
		UPDATE {db_prefix}boards
		SET ' . ($row['approved'] ? '
			num_posts = CASE WHEN num_posts = {int:no_posts} THEN 0 ELSE num_posts - 1 END' : '
			unapproved_posts = CASE WHEN unapproved_posts = {int:no_unapproved} THEN 0 ELSE unapproved_posts - 1 END') . '
		WHERE id_board = {int:id_board}', array('no_posts' => 0, 'no_unapproved' => 0, 'id_board' => $row['id_board']));
    // If the poster was registered and the board this message was on incremented
    // the member's posts when it was posted, decrease his or her post count.
    if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) {
        updateMemberData($row['id_member'], array('posts' => '-'));
    }
    // Only remove posts if they're not recycled.
    if (!$recycle) {
        require_once $sourcedir . '/lib/Subs-Ratings.php';
        require_once $sourcedir . '/lib/Subs-Activities.php';
        // Remove the message + maybe its cached version
        smf_db_query('
			DELETE m.*, c.* FROM {db_prefix}messages AS m LEFT JOIN {db_prefix}messages_cache AS c ON (c.id_msg = m.id_msg)
			WHERE m.id_msg = {int:id_msg}', array('id_msg' => $message));
        if (!empty($modSettings['search_custom_index_config'])) {
            $customIndexSettings = unserialize($modSettings['search_custom_index_config']);
            $words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true);
            if (!empty($words)) {
                smf_db_query('
					DELETE FROM {db_prefix}log_search_words
					WHERE id_word IN ({array_int:word_list})
						AND id_msg = {int:id_msg}', array('word_list' => $words, 'id_msg' => $message));
            }
        }
        // Delete attachment(s) if they exist.
        require_once $sourcedir . '/lib/Subs-ManageAttachments.php';
        $attachmentQuery = array('attachment_type' => 0, 'id_msg' => $message);
        removeAttachments($attachmentQuery);
        // remove likes and like_cache
        $likes_to_remove = array($message);
        Ratings::removeByPosts($likes_to_remove);
        // remove activities related to this post
        aStreamRemoveByContent($likes_to_remove);
    }
    // Update the pesky statistics.
    updateStats('message');
    updateStats('topic');
    updateSettings(array('calendar_updated' => time()));
    // And now to update the last message of each board we messed with.
    require_once $sourcedir . '/lib/Subs-Post.php';
    if ($recycle) {
        updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
    } else {
        updateLastMessages($row['id_board']);
    }
    return false;
}
Example #22
0
<?php

use Project\Classes\DB\DB;
//require_once '../../../autoloader.php';
require_once '../../autoloader.php';
require_once '../../Rating_System/Model/Ratings.php';
require_once '../../Rating_System/database.php';
$db = Database::getDB();
$rating_id = $_POST['rating_id'];
// Get the product data
$updateRating = new Ratings();
$editRatings = $updateRating->editRating($rating_id);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/Assets/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="/Assets/css/style.css"/>
    <title> Edit Ratings Form</title>
</head>
<body>
<div class="container">
    <form action="/admin/editedRating" method="post">
        <fieldset class="form-group">
            <input type="hidden" name="rating_id" value="<?php 
echo $rating_id;
?>
">
Example #23
0
function RecentPosts()
{
    global $sourcedir, $txt, $scripturl, $user_info, $context, $modSettings, $board, $memberContext;
    if (!empty($modSettings['karmaMode'])) {
        require_once $sourcedir . '/lib/Subs-Ratings.php';
        $boards_like_see = boardsAllowedTo('like_see');
        $boards_like_give = boardsAllowedTo('like_give');
    } else {
        $context['can_see_like'] = $context['can_give_like'] = false;
        $boards_like_see = array();
        $boards_like_give = array();
    }
    $context['time_now'] = time();
    $context['need_synhlt'] = true;
    EoS_Smarty::loadTemplate('recent');
    $context['template_functions'] = 'recentposts';
    $context['messages_per_page'] = $modSettings['defaultMaxMessages'];
    $context['page_number'] = isset($_REQUEST['start']) ? $_REQUEST['start'] / $context['messages_per_page'] : 0;
    $context['page_title'] = $txt['recent_posts'] . ((int) $context['page_number'] > 0 ? ' - ' . $txt['page'] . ' ' . ($context['page_number'] + 1) : '');
    $boards_hidden_1 = boardsAllowedTo('see_hidden1');
    $boards_hidden_2 = boardsAllowedTo('see_hidden2');
    $boards_hidden_3 = boardsAllowedTo('see_hidden3');
    if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) {
        $_REQUEST['start'] = 95;
    }
    $query_parameters = array();
    if (!empty($_REQUEST['c']) && empty($board)) {
        $_REQUEST['c'] = explode(',', $_REQUEST['c']);
        foreach ($_REQUEST['c'] as $i => $c) {
            $_REQUEST['c'][$i] = (int) $c;
        }
        if (count($_REQUEST['c']) == 1) {
            $request = smf_db_query('
				SELECT name
				FROM {db_prefix}categories
				WHERE id_cat = {int:id_cat}
				LIMIT 1', array('id_cat' => $_REQUEST['c'][0]));
            list($name) = mysql_fetch_row($request);
            mysql_free_result($request);
            if (empty($name)) {
                fatal_lang_error('no_access', false);
            }
            $context['linktree'][] = array('url' => $scripturl . '#c' . (int) $_REQUEST['c'], 'name' => $name);
        }
        $request = smf_db_query('
			SELECT b.id_board, b.num_posts
			FROM {db_prefix}boards AS b
			WHERE b.id_cat IN ({array_int:category_list})
				AND {query_see_board}', array('category_list' => $_REQUEST['c']));
        $total_cat_posts = 0;
        $boards = array();
        while ($row = mysql_fetch_assoc($request)) {
            $boards[] = $row['id_board'];
            $total_cat_posts += $row['num_posts'];
        }
        mysql_free_result($request);
        if (empty($boards)) {
            fatal_lang_error('error_no_boards_selected');
        }
        $query_this_board = 'b.id_board IN ({array_int:boards})';
        $query_parameters['boards'] = $boards;
        // If this category has a significant number of posts in it...
        if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) {
            $query_this_board .= '
					AND m.id_msg >= {int:max_id_msg}';
            $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 400 - $_REQUEST['start'] * 7);
        }
        $context['page_index'] = $total_cat_posts ? constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), $context['messages_per_page'], false) : '';
    } elseif (!empty($_REQUEST['boards'])) {
        $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
        foreach ($_REQUEST['boards'] as $i => $b) {
            $_REQUEST['boards'][$i] = (int) $b;
        }
        $request = smf_db_query('
			SELECT b.id_board, b.num_posts
			FROM {db_prefix}boards AS b
			WHERE b.id_board IN ({array_int:board_list})
				AND {query_see_board}
			LIMIT {int:limit}', array('board_list' => $_REQUEST['boards'], 'limit' => count($_REQUEST['boards'])));
        $total_posts = 0;
        $boards = array();
        while ($row = mysql_fetch_assoc($request)) {
            $boards[] = $row['id_board'];
            $total_posts += $row['num_posts'];
        }
        mysql_free_result($request);
        if (empty($boards)) {
            fatal_lang_error('error_no_boards_selected');
        }
        $query_this_board = 'b.id_board IN ({array_int:boards})';
        $query_parameters['boards'] = $boards;
        // If these boards have a significant number of posts in them...
        if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) {
            $query_this_board .= '
					AND m.id_msg >= {int:max_id_msg}';
            $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 500 - $_REQUEST['start'] * 9);
        }
        $context['page_index'] = $total_posts ? constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), $context['messages_per_page'], false) : '';
    } elseif (!empty($board)) {
        $request = smf_db_query('
			SELECT num_posts
			FROM {db_prefix}boards
			WHERE id_board = {int:current_board}
			LIMIT 1', array('current_board' => $board));
        list($total_posts) = mysql_fetch_row($request);
        mysql_free_result($request);
        $query_this_board = 'b.id_board = {int:board}';
        $query_parameters['board'] = $board;
        // If this board has a significant number of posts in it...
        if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) {
            $query_this_board .= '
					AND m.id_msg >= {int:max_id_msg}';
            $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 600 - $_REQUEST['start'] * 10);
        }
        $context['page_index'] = $total_posts ? constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), $context['messages_per_page'], true) : '';
    } else {
        $query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
					AND b.id_board != {int:recycle_board}' : '') . '
					AND m.id_msg >= {int:max_id_msg}';
        $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 100 - $_REQUEST['start'] * 6);
        $query_parameters['recycle_board'] = $modSettings['recycle_board'];
        // !!! This isn't accurate because we ignore the recycle bin.
        $context['page_index'] = constructPageIndex($scripturl . '?action=recent', $_REQUEST['start'], min(100, $modSettings['totalMessages']), $context['messages_per_page'], false);
    }
    $context['linktree'][] = array('url' => $scripturl . '?action=recent' . (empty($board) ? empty($_REQUEST['c']) ? '' : ';c=' . (int) $_REQUEST['c'] : ';board=' . $board . '.0'), 'name' => $context['page_title']);
    $context['start'] = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
    $key = 'recent-' . $user_info['id'] . '-' . md5(serialize(array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start'];
    if (empty($modSettings['cache_enable']) || ($messages = CacheAPI::getCache($key, 120)) == null) {
        $done = false;
        while (!$done) {
            // Find the 10 most recent messages they can *view*.
            // !!!SLOW This query is really slow still, probably?
            $request = smf_db_query('
				SELECT m.id_msg
				FROM {db_prefix}messages AS m
					INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
				WHERE ' . $query_this_board . '
					AND m.approved = {int:is_approved}
				ORDER BY m.id_msg DESC
				LIMIT {int:offset}, {int:limit}', array_merge($query_parameters, array('is_approved' => 1, 'offset' => $_REQUEST['start'], 'limit' => $context['messages_per_page'])));
            // If we don't have 10 results, try again with an unoptimized version covering all rows, and cache the result.
            if (isset($query_parameters['max_id_msg']) && mysql_num_rows($request) < $context['messages_per_page']) {
                mysql_free_result($request);
                $query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board);
                $cache_results = true;
                unset($query_parameters['max_id_msg']);
            } else {
                $done = true;
            }
        }
        $messages = array();
        while ($row = mysql_fetch_assoc($request)) {
            $messages[] = $row['id_msg'];
        }
        mysql_free_result($request);
        if (!empty($cache_results)) {
            CacheAPI::putCache($key, $messages, 120);
        }
    }
    // Nothing here... Or at least, nothing you can see...
    if (empty($messages)) {
        $context['posts'] = array();
        return;
    }
    // Get all the most recent posts.
    $request = smf_db_query('
		SELECT
			m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.modified_time, m.body, m.icon, m.id_topic, t.id_board, b.id_cat, mc.body AS cached_body,
			b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m2.id_member AS id_first_member, ' . (!empty($modSettings['karmaMode']) ? 'lc.likes_count, lc.like_status, lc.updated AS like_updated, l.rtype AS liked, ' : '0 AS likes_count, 0 AS like_status, 0 AS like_updated, 0 AS liked, ') . '
			IFNULL(mem2.real_name, m2.poster_name) AS first_poster_name, t.id_first_msg, m2.subject AS first_subject, m2.poster_time AS time_started,
			IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
		FROM {db_prefix}messages AS m
			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
			INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
			INNER JOIN {db_prefix}messages AS m2 ON (m2.id_msg = t.id_first_msg)
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
			LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = m2.id_member)' . (!empty($modSettings['karmaMode']) ? '
			LEFT JOIN {db_prefix}likes AS l ON (l.id_msg = m.id_msg AND l.ctype = 1 AND l.id_user = {int:id_user})
			LEFT JOIN {db_prefix}like_cache AS lc ON (lc.id_msg = m.id_msg AND lc.ctype = 1)' : '') . '
			LEFT JOIN {db_prefix}messages_cache AS mc ON (mc.id_msg = m.id_msg AND mc.style = {int:style} AND mc.lang = {int:lang})
		WHERE m.id_msg IN ({array_int:message_list})
		ORDER BY m.id_msg DESC
		LIMIT ' . count($messages), array('message_list' => $messages, 'style' => $user_info['smiley_set_id'], 'lang' => $user_info['language_id'], 'id_user' => $user_info['id']));
    $counter = $_REQUEST['start'] + 1;
    $context['posts'] = array();
    $board_ids = array('own' => array(), 'any' => array());
    $userids = array();
    while ($row = mysql_fetch_assoc($request)) {
        $check_boards = array(0, $row['id_board']);
        // 0 is for admin
        $context['can_see_hidden_level1'] = count(array_intersect($check_boards, $boards_hidden_1)) > 0;
        $context['can_see_hidden_level2'] = count(array_intersect($check_boards, $boards_hidden_2)) > 0;
        $context['can_see_hidden_level3'] = count(array_intersect($check_boards, $boards_hidden_3)) > 0;
        $context['can_see_like'] = count(array_intersect($check_boards, $boards_like_see)) > 0;
        $context['can_give_like'] = count(array_intersect($check_boards, $boards_like_give)) > 0;
        // Censor everything.
        censorText($row['body']);
        censorText($row['subject']);
        getCachedPost($row);
        // this will also care about bbc parsing...
        // And build the array.
        $thref = URL::topic($row['id_topic'], $row['first_subject'], 0, false, '.msg' . $row['id_msg'], '#' . $row['id_msg']);
        $topichref = URL::topic($row['id_topic'], $row['first_subject'], 0);
        $bhref = URL::board($row['id_board'], $row['bname'], 0, false);
        $fhref = empty($row['id_first_member']) ? '' : URL::user($row['id_first_member'], $row['first_poster_name']);
        $userids[$row['id_msg']] = $row['id_member'];
        $context['posts'][$row['id_msg']] = array('id' => $row['id_msg'], 'counter' => $counter++, 'sequence_number' => true, 'icon' => $row['icon'], 'icon_url' => getPostIcon($row['icon']), 'category' => array('id' => $row['id_cat'], 'name' => $row['cname'], 'href' => $scripturl . '#c' . $row['id_cat'], 'link' => '<a href="' . $scripturl . '#c' . $row['id_cat'] . '">' . $row['cname'] . '</a>'), 'board' => array('id' => $row['id_board'], 'name' => $row['bname'], 'href' => $bhref, 'link' => '<a href="' . $bhref . '">' . $row['bname'] . '</a>'), 'href' => $thref, 'link' => '<a href="' . $thref . '" rel="nofollow">' . $row['subject'] . '</a>', 'start' => $row['num_replies'], 'subject' => $row['subject'], 'time' => timeformat($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'first_poster' => array('id' => $row['id_first_member'], 'name' => $row['first_poster_name'], 'href' => $fhref, 'link' => empty($row['id_first_member']) ? $row['first_poster_name'] : '<a href="' . $fhref . '">' . $row['first_poster_name'] . '</a>', 'time' => timeformat($row['time_started'])), 'topic' => array('id' => $row['id_topic'], 'href' => $topichref, 'link' => '<a href="' . $topichref . '" rel="nofollow">' . $row['first_subject'] . '</a>'), 'permahref' => URL::parse('?msg=' . $row['id_msg']), 'permalink' => $txt['view_in_thread'], 'id_member' => $row['id_member'], 'body' => $row['body'], 'can_reply' => false, 'can_mark_notify' => false, 'can_delete' => false, 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()), 'likes_count' => $row['likes_count'], 'like_status' => $row['like_status'], 'liked' => $row['liked'], 'like_updated' => $row['like_updated'], 'likers' => '', 'likelink' => '');
        if ($context['can_see_like']) {
            Ratings::addContent($context['posts'][$row['id_msg']], $context['can_give_like'], $context['time_now']);
        }
        if ($user_info['id'] == $row['id_first_member']) {
            $board_ids['own'][$row['id_board']][] = $row['id_msg'];
        }
        $board_ids['any'][$row['id_board']][] = $row['id_msg'];
    }
    mysql_free_result($request);
    loadMemberData(array_unique($userids));
    // There might be - and are - different permissions between any and own.
    $permissions = array('own' => array('post_reply_own' => 'can_reply', 'delete_own' => 'can_delete'), 'any' => array('post_reply_any' => 'can_reply', 'mark_any_notify' => 'can_mark_notify', 'delete_any' => 'can_delete'));
    // Now go through all the permissions, looking for boards they can do it on.
    foreach ($permissions as $type => $list) {
        foreach ($list as $permission => $allowed) {
            // They can do it on these boards...
            $boards = boardsAllowedTo($permission);
            // If 0 is the only thing in the array, they can do it everywhere!
            if (!empty($boards) && $boards[0] == 0) {
                $boards = array_keys($board_ids[$type]);
            }
            // Go through the boards, and look for posts they can do this on.
            foreach ($boards as $board_id) {
                // Hmm, they have permission, but there are no topics from that board on this page.
                if (!isset($board_ids[$type][$board_id])) {
                    continue;
                }
                // Okay, looks like they can do it for these posts.
                foreach ($board_ids[$type][$board_id] as $counter) {
                    if ($type == 'any' || $context['posts'][$counter]['id_member'] == $user_info['id']) {
                        $context['posts'][$counter][$allowed] = true;
                    }
                }
            }
        }
    }
    $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
    foreach ($context['posts'] as $counter => &$post) {
        loadMemberContext($post['id_member']);
        $post['member'] =& $memberContext[$post['id_member']];
        // Some posts - the first posts - can't just be deleted.
        $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible'];
        // And some cannot be quoted...
        $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled;
    }
}
Example #24
0
<?php

use Project\Classes\DB\DB;
include '../../autoloader.php';
require_once '../../Rating_System/Model/Ratings.php';
require_once '../../Rating_System/database.php';
$db = Database::getDB();
// Get the value from the form
$rating_id = $_POST['rating_id'];
$total_votes = $_POST['total_votes'];
$total_value = $_POST['total_value'];
$used_ips = $_POST['used_ips'];
$date = $_POST['date'];
// Validate inputs
if (empty($total_votes) || empty($total_value) || empty($used_ips) || empty($date)) {
    echo "<span style='color:red;font-size:24px;'>";
    $error = "Invalid Rating data. Check all fields and try again.";
    echo $error;
    echo "</span>";
} else {
    // If valid, update the Rating data to the database
    $ratingData = new Ratings();
    $ratingData->ratingUpdate($total_votes, $total_value, $used_ips, $date, $rating_id);
    // Display the Rating List page
    //  header('location: ../View/Ratings_Index.php');
    header('location: /admin/rating');
}
Example #25
0
 /**
  * Retrieve all the images in a pool, given a pool ID.
  *
  * @param PageRequestEvent $event
  * @param int $poolID
  */
 private function get_posts($event, $poolID)
 {
     global $config, $user, $database;
     $pageNumber = int_escape($event->get_arg(2));
     if (is_null($pageNumber) || !is_numeric($pageNumber)) {
         $pageNumber = 0;
     } else {
         if ($pageNumber <= 0) {
             $pageNumber = 0;
         } else {
             $pageNumber--;
         }
     }
     $poolID = int_escape($poolID);
     $pool = $this->get_pool($poolID);
     $imagesPerPage = $config->get_int("poolsImagesPerPage");
     // WE CHECK IF THE EXTENSION RATING IS INSTALLED, WHICH VERSION AND IF IT
     // WORKS TO SHOW/HIDE SAFE, QUESTIONABLE, EXPLICIT AND UNRATED IMAGES FROM USER
     if (ext_is_live("Ratings")) {
         $rating = Ratings::privs_to_sql(Ratings::get_user_privs($user));
     }
     if (isset($rating) && !empty($rating)) {
         $result = $database->get_all("\n\t\t\t\t\tSELECT p.image_id\n\t\t\t\t\tFROM pool_images AS p\n\t\t\t\t\tINNER JOIN images AS i ON i.id = p.image_id\n\t\t\t\t\tWHERE p.pool_id = :pid AND i.rating IN ({$rating})\n\t\t\t\t\tORDER BY p.image_order ASC\n\t\t\t\t\tLIMIT :l OFFSET :o", array("pid" => $poolID, "l" => $imagesPerPage, "o" => $pageNumber * $imagesPerPage));
         $totalPages = ceil($database->get_one("\n\t\t\t\t\tSELECT COUNT(*) \n\t\t\t\t\tFROM pool_images AS p\n\t\t\t\t\tINNER JOIN images AS i ON i.id = p.image_id\n\t\t\t\t\tWHERE pool_id=:pid AND i.rating IN ({$rating})", array("pid" => $poolID)) / $imagesPerPage);
     } else {
         $result = $database->get_all("\n\t\t\t\t\tSELECT image_id\n\t\t\t\t\tFROM pool_images\n\t\t\t\t\tWHERE pool_id=:pid\n\t\t\t\t\tORDER BY image_order ASC\n\t\t\t\t\tLIMIT :l OFFSET :o", array("pid" => $poolID, "l" => $imagesPerPage, "o" => $pageNumber * $imagesPerPage));
         $totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", array("pid" => $poolID)) / $imagesPerPage);
     }
     $images = array();
     foreach ($result as $singleResult) {
         $images[] = Image::by_id($singleResult["image_id"]);
     }
     $this->theme->view_pool($pool, $images, $pageNumber + 1, $totalPages);
 }
Example #26
0
    echo '<td><a href="https://www.reddit.com/user/' . $review_user->getUsername() . '/">/u/' . $review_user->getUsername() . '</a></td></tr>';
}
?>
			</table>
                <?php 
if (Auth::checkIfAuthenticated()) {
    ?>
                    <form action="" method="POST">
                        <?php 
    $review = UserReviews::getUserReview($game, $platform, $user);
    ?>
                        <div class="form-group">
                            Submit User Review
                            <select name="submit_game_rating" class="form-control">
                                <?php 
    $ratings = Ratings::getAllRatings();
    foreach ($ratings as $rating) {
        echo '<option value="' . $rating->getId() . '"';
        if ($review != null && $review->getRating() == $rating->getId()) {
            echo ' selected="selected" ';
        }
        echo '>' . $rating->getTitle() . "</option>";
    }
    ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <textarea class="form-control" name="submit_game_review"><?php 
    if ($review != null) {
        echo $review->getReview();
    }
Example #27
0
<html>
<head>
    <meta charset="UTF-8">
    <title>Rate Movie</title>
    <script src="jquery.js" type="text/javascript"></script>
    <link rel="stylesheet" href="rating.css" />
    <script type="text/javascript" src="rating.js"></script>
</head>
<body>

<?php 
for ($i = 0; $i < count($ids); $i++) {
    //$rating_tableName = 'ratings';
    $id = $ids[$i];
    $disVotes_user = new Ratings();
    $row = $disVotes_user->displayRating_user($id);
    if (!$row) {
        echo "<span style='color: red;'> Error! No record found in database!! </span>";
    }
    /*
        while($row = $queryPre->fetch())
        {
    
            $v = $row['total_votes'];
            $tv = $row['total_value'];
            $rat = $tv/$v;
            var_dump($rat);
        }
    */
    $v = $row['total_votes'];
Example #28
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.1
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     $this->loadJs($parameters);
     $parameters['page'] = $parameters['page'] === false ? $GLOBALS['wgTitle'] : Title::newFromText($parameters['page']);
     static $ratingStarNr = 0;
     $ratingStarNr++;
     $inputs = array();
     for ($i = 0; $i < 5; $i++) {
         $inputs[] = Html::element('input', array('class' => 'starrating', 'type' => 'radio', 'name' => 'ratingstars_' . $ratingStarNr, 'value' => $i, 'page' => $parameters['page']->getFullText(), 'tag' => $parameters['tag']));
     }
     if ($parameters['incsummary']) {
         array_unshift($inputs, htmlspecialchars(Ratings::getRatingSummaryMessage($parameters['page'], $parameters['tag'])) . '<br />');
     }
     return Html::rawElement('div', array('style' => 'display:none; position:static', 'class' => 'starrating-div'), implode('', $inputs));
 }
Example #29
0
/**
 * generate the rating widget
 */
function GetRatingWidget()
{
    global $modSettings, $user_info, $context, $txt;
    if ($user_info['is_guest']) {
        AjaxErrorMsg($txt['no_like_for_guests']);
    }
    $xml = isset($_REQUEST['xml']);
    $content_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
    $ctype = isset($_REQUEST['c']) ? (int) $_REQUEST['c'] : 0;
    if (0 == $ctype || 0 == $content_id) {
        AjaxErrorMsg($txt['rating_invalid_params']);
    }
    if ($xml) {
        EoS_Smarty::loadTemplate('xml_blocks');
        $context['template_functions'] = 'ratingwidget';
    } else {
        EoS_Smarty::loadTemplate('ratings/widget');
    }
    // todo: allow rating without ajax / js
    $request = smf_db_query('SELECT m.id_msg, m.id_topic, m.id_board FROM {db_prefix}messages AS m WHERE m.id_msg = {int:id} LIMIT 1', array('id' => $content_id));
    list($id_msg, $id_topic, $id_board) = mysql_fetch_row($request);
    mysql_free_result($request);
    $context['result_count'] = 0;
    $uniques = array(true, false);
    foreach ($uniques as $uniqueness) {
        foreach ($modSettings['ratings'] as $key => $rating) {
            if ($rating['unique'] != $uniqueness) {
                continue;
            }
            if (Ratings::isAllowed($key, $id_board)) {
                $context['result_count']++;
                $context['ratings'][] = array('rtype' => (int) $key, 'label' => $rating['text'], 'unique' => $rating['unique']);
            }
        }
    }
    $context['content_id'] = $content_id;
    $context['json_data'] = htmlspecialchars(json_encode(array('id' => $content_id, 'error_text' => $txt['ratingwidget_error'])));
}
Example #30
0
 public function receive_event(Event $event)
 {
     global $config, $database, $page, $user;
     if (is_null($this->theme)) {
         $this->theme = get_theme_object($this);
     }
     if ($event instanceof AdminBuildingEvent) {
         $this->theme->display_bulk_rater();
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("admin/bulk_rate")) {
         global $database, $user, $page;
         if (!$user->is_admin()) {
             throw PermissionDeniedException();
         } else {
             $n = 0;
             while (true) {
                 $images = Image::find_images($n, 100, Tag::explode($_POST["query"]));
                 if (count($images) == 0) {
                     break;
                 }
                 foreach ($images as $image) {
                     send_event(new RatingSetEvent($image, $user, $_POST['rating']));
                 }
                 $n += 100;
             }
             #$database->execute("
             #	update images set rating=? where images.id in (
             #		select image_id from image_tags join tags
             #		on image_tags.tag_id = tags.id where tags.tag = ?);
             #	", array($_POST["rating"], $_POST["tag"]));
             $page->set_mode("redirect");
             $page->set_redirect(make_link("admin"));
         }
     }
     if ($event instanceof InitExtEvent) {
         if ($config->get_int("ext_ratings2_version") < 2) {
             $this->install();
         }
         $config->set_default_string("ext_rating_anon_privs", 'squ');
         $config->set_default_string("ext_rating_user_privs", 'sqeu');
         $config->set_default_string("ext_rating_admin_privs", 'sqeu');
     }
     if ($event instanceof RatingSetEvent) {
         $this->set_rating($event->image->id, $event->rating);
     }
     if ($event instanceof ImageInfoBoxBuildingEvent) {
         if ($this->can_rate()) {
             $event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80);
         }
     }
     if ($event instanceof ImageInfoSetEvent) {
         if ($this->can_rate() && isset($_POST["rating"])) {
             send_event(new RatingSetEvent($event->image, $user, $_POST['rating']));
         }
     }
     if ($event instanceof SetupBuildingEvent) {
         $privs = array();
         $privs['Safe Only'] = 's';
         $privs['Safe and Unknown'] = 'su';
         $privs['Safe and Questionable'] = 'sq';
         $privs['Safe, Questionable, Unknown'] = 'squ';
         $privs['All'] = 'sqeu';
         $sb = new SetupBlock("Image Ratings");
         $sb->add_choice_option("ext_rating_anon_privs", $privs, "Anonymous: ");
         $sb->add_choice_option("ext_rating_user_privs", $privs, "<br>Users: ");
         $sb->add_choice_option("ext_rating_admin_privs", $privs, "<br>Admins: ");
         $event->panel->add_block($sb);
     }
     if ($event instanceof ParseLinkTemplateEvent) {
         $event->replace('$rating', $this->theme->rating_to_name($event->image->rating));
     }
     if ($event instanceof SearchTermParseEvent) {
         $matches = array();
         if (is_null($event->term) && $this->no_rating_query($event->context)) {
             $set = Ratings::privs_to_sql(Ratings::get_user_privs($user));
             $event->add_querylet(new Querylet("rating IN ({$set})"));
         }
         if (preg_match("/^rating=([sqeu]+)\$/", $event->term, $matches)) {
             $sqes = $matches[1];
             $arr = array();
             for ($i = 0; $i < strlen($sqes); $i++) {
                 $arr[] = "'" . $sqes[$i] . "'";
             }
             $set = join(', ', $arr);
             $event->add_querylet(new Querylet("rating IN ({$set})"));
         }
         if (preg_match("/^rating=(safe|questionable|explicit|unknown)\$/", strtolower($event->term), $matches)) {
             $text = $matches[1];
             $char = $text[0];
             $event->add_querylet(new Querylet("rating = ?", array($char)));
         }
     }
 }