Note: I made this for a user on the mkportal.it forums. I have no use for this hack myself so I will not spend much time answering questions about it or giving support unless someone finds a major bug. But maybe someone else will want this hack so I am posting it.

FIND in /mkportal/modules/reviews/tpl_reviews.php:
function review_show($navbar, $maintit, $content, $submit, $stat, $toolbar, $pages, $utonline) {
REPLACE WITH://function review_show($navbar, $maintit, $content, $submit, $stat, $toolbar, $pages, $utonline) {
//Random Reviews Hack
function review_show($navbar, $maintit, $content, $content_r='', $submit, $stat, $toolbar, $pages, $utonline) {
FIND in function review_show: {$toolbar}
ADD ABOVE:<!-- Random Reviews Hack -->
{$content_r}
<!-- end Random Reviews Hack -->
FIND:function row_entry($id, $name, $description, $trate, $rate, $width2, $width, $autore, $image, $field1, $field2, $field3, $field4, $field5, $field6, $field7, $review) {
ADD ABOVE:// Random Reviews Hack
function random_reviews_open() {
global $mkportals, $mklib;
return <<<EOF
<table width="98%" border="0" cellspacing="1" cellpadding="0" align="center" class="moduleborder">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="modulebg">
<tr>
<td width="100%" height="25" class="tdblock"> <img src="$mklib->images/arrow.gif" alt="" />Random Reviews</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="5">
EOF;
}
function random_reviews_close() {
global $mkportals, $mklib;
return <<<EOF
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
EOF;
}
function row_main_entries_r() {
global $mkportals, $mklib;
return <<<EOF
<tr>
<th class="modulex" width="40"> </th>
<th class="modulex" width="*">{$mklib->lang['re_name']}</th>
<th class="modulex" width="75" align="center">{$mklib->lang['re_votes']}</th>
<th class="modulex" width="75" align="center">{$mklib->lang['re_clicks']}</th>
<th class="modulex" width="150" align="center">{$mklib->lang['re_insdate']}</th>
</tr>
EOF;
}
function row_main_entries_content_r($name_r, $trate_r, $description_r, $click_r, $data_r) {
global $mkportals, $mklib;
return <<<EOF
<tr>
<td class="modulecell" width="40" align="center"><img src="$mklib->images/entry.gif" alt="" /></td>
<td class="modulecell" width="*">{$name_r}
{$description_r}</td>
<td class="modulecell" width="75" align="center">{$trate_r}</td>
<td class="modulecell" width="75" align="center">{$click_r}</td>
<td class="modulecell" width="150" align="center">{$data_r}</td>
</tr>
EOF;
}
// end Random Reviews Hack
----------------------------------------------FIND in /mkportal/modules/reviews/index.php (function reviews_show):
$submit = " <a href="index.php?ind=reviews&op=submit_file">[ {$mklib->lang['re_send']} ]</a> ";
ADD ABOVE:// Random Reviews Hack
$content_r = $this->tpl->random_reviews_open();
$content_r .= $this->tpl->row_main_entries_r();
$limit = 5;
// Get highest image id
$query2 = $DB->query("SELECT MAX(id) AS maxid FROM mkp_reviews");
$row2 = $DB->fetch_row($query2);
$maxid = $row2['maxid'];
// Generate random start number
$start = rand(0, ($maxid -$limit));
// Generate 10 times the number of IDs set in $limit
// This is an attempt to make up for deleted IDs in the list
$limit10 = $limit * 10;
// Generate an array of random numbers between $start and $maxid
for ($i=0; $i < $limit10; $i++) {
$random = rand($start, $maxid);
$numbers[] = $random;
}
$query3 = $DB->query("SELECT id, title, description, click, date, trate FROM mkp_reviews WHERE validate = '1' AND id IN (".implode(',', $numbers ).") LIMIT $limit");
$numrows = $DB->get_num_rows($query3);
// If not enough IDs returned in query run backup "ORDER BY RAND()" query
// This query is more resource intensive but it will probably only be needed for very small reviews databases
if ($numrows < $limit) {
$query3 = $DB->query( "SELECT id, title, description, click, date, trate FROM mkp_reviews WHERE validate = '1' ORDER BY RAND() LIMIT $limit");
}
while( $row3 = $DB->fetch_row($query3) ) {
$iden_r = $row3['id'];
$name_r = $row3['title'];
$trate_r = $row3['trate'];
$description_r = $row3['description'];
$click_r = $row3['click'];
$data_r = $mklib->create_date($row3['date'], "short");
$name_r ="<a href='index.php?ind=reviews&op=entry_view&iden=$iden_r'>$name_r</a>";
$content_r .= $this->tpl->row_main_entries_content_r($name_r, $trate_r, $description_r, $click_r, $data_r);
}
$content_r .= $this->tpl->random_reviews_close();
// end Random Reviews Hack
Now you need to FIND every occurance of this string in /mkportal/modules/reviews/index.php. There are many places in the file where this must be replaced.$output = $this->tpl->review_show($navbar, $maintit, $content, $submit, $stat, $toolbar, $show_pages, $utonline);REPLACE every instance in the file WITH:
//$output = $this->tpl->review_show($navbar, $maintit, $content, $submit, $stat, $toolbar, $show_pages, $utonline); // Random Reviews Hack $output = $this->tpl->review_show($navbar, $maintit, $content, $content_r, $submit, $stat, $toolbar, $show_pages, $utonline);Now to show random reviews in other screens (for example index.php?ind=reviews&op=section_view&idev=1) all you need to do is duplicate the hack I posted for index.php(function reviews_show) and add it to the other functions where you want it.
You may want to edit the queries to show only random reviews from a specific category.
Here is how to do it for function section_view:
FIND in function section_view:
$submit = " <a href="index.php?ind=reviews&op=submit_file">[ {$mklib->lang['re_send']} ]</a> ";
ADD ABOVE:// Random Reviews Hack
$content_r = $this->tpl->random_reviews_open();
$content_r .= $this->tpl->row_main_entries_r();
$limit = 5;
// Get highest image id
$query2 = $DB->query("SELECT MAX(id) AS maxid FROM mkp_reviews WHERE id_cat = '$idev'");
$row2 = $DB->fetch_row($query2);
$maxid = $row2['maxid'];
// Generate random start number
$start = rand(0, ($maxid -$limit));
// Generate 10 times the number of IDs set in $limit
// This is an attempt to make up for deleted IDs in the list
$limit10 = $limit * 10;
// Generate an array of random numbers between $start and $maxid
for ($i=0; $i < $limit10; $i++) {
$random = rand($start, $maxid);
$numbers[] = $random;
}
$query3 = $DB->query("SELECT id, title, description, click, date, trate FROM mkp_reviews WHERE id_cat = '$idev' AND validate = '1' AND id IN (".implode(',', $numbers ).") LIMIT $limit");
$numrows = $DB->get_num_rows($query3);
// If not enough IDs returned in query run backup "ORDER BY RAND()" query
// This query is more resource intensive but it will probably only be needed for very small reviews databases
if ($numrows < $limit) {
$query3 = $DB->query( "SELECT id, title, description, click, date, trate FROM mkp_reviews WHERE id_cat = '$idev' AND validate = '1' ORDER BY RAND() LIMIT $limit");
}
while( $row3 = $DB->fetch_row($query3) ) {
$iden_r = $row3['id'];
$name_r = $row3['title'];
$trate_r = $row3['trate'];
$description_r = $row3['description'];
$click_r = $row3['click'];
$data_r = $mklib->create_date($row3['date'], "short");
$name_r ="<a href='index.php?ind=reviews&op=entry_view&iden=$iden_r'>$name_r</a>";
$content_r .= $this->tpl->row_main_entries_content_r($name_r, $trate_r, $description_r, $click_r, $data_r);
}
$content_r .= $this->tpl->random_reviews_close();
// end Random Reviews Hack
Of course you can simplify my random id generation code to only use "ORDER BY RAND() if you prefer but doing so would make random id generation very resource intensive for databases with over about 100 reviews.













