$PID in theme.php $PID in theme.php
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

$PID in theme.php

Started by morch, October 28, 2009, 11:30:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

morch

I need to change the voting system to % - which means I have to make it possible to select from 0 to 100 points.

I've made a for .. next in theme.php that generates a table with links to ratepic.php but I can not figure out how to get the value for $pid:

$i=0;
while($i<=100)
  {
  $ending="s";
  if ($i == 1) $ending="";
  $votetable .= "<td><a title=' Give this picture " . $i ." point" . $ending . "' href='ratepic.php?pic=" . $pid . "&amp;rate=" . $i . "'>" . $i . "-" . $pid . "</a></td>";
  if ($i % 10 == 9) $votetable .= "</tr><tr>";
  $i++;
  }

// HTML template for the image rating box
if (!isset($template_image_rating)) { //{THEMES}
$template_image_rating = <<<EOT

<table align='center'><tr><td colspan='10'><b>Cast your vote by clicking a number below:</b></td></tr><tr>  $votetable  </tr></table>

EOT;
}  //{THEMES}




I've searched everywhere, but cant find a solution.

Should I make this tavle somewhere else (in another of the php files)?

Joachim Müller

Well, your little table just takes care of the visuals, but it doesn't take care of the logic (the calculation of the rating), which resides in many different places in coppermine's core code. I'm afraid that things won't be that simple...

morch

I figured that out, and did it the long and boring ;) way by changing the theme.php HTML template for the image rating box to a table :

<table align="center">
  <tr>
  <td colspan='10'><b>Cast your vote by clicking a number below:</b></td>
  </tr>
  <tr>
    <td align="center"><a title="Award this picture 0 points" href="{RATE0}" rel="nofollow">0</a></td>
    <td align="center"><a title="Award this picture 1 point" href="{RATE1}" rel="nofollow">1</a></td>
    <td align="center"><a title="Award this picture 2 points" href="{RATE2}" rel="nofollow">2</a></td>
    <td align="center"><a title="Award this picture 3 points" href="{RATE3}" rel="nofollow">3</a></td>
    <td align="center"><a title="Award this picture 4 points" href="{RATE4}" rel="nofollow">4</a></td>
    <td align="center"><a title="Award this picture 5 points" href="{RATE5}" rel="nofollow">5</a></td>
    <td align="center"><a title="Award this picture 6 points" href="{RATE6}" rel="nofollow">6</a></td>
    <td align="center"><a title="Award this picture 7 points" href="{RATE7}" rel="nofollow">7</a></td>
    <td align="center"><a title="Award this picture 8 points" href="{RATE8}" rel="nofollow">8</a></td>
    <td align="center"><a title="Award this picture 9 points" href="{RATE9}" rel="nofollow">9</a></td>
  </tr>
....
  <tr>
    <td align="center"><a title="Award this picture 90 points" href="{RATE90}" rel="nofollow">90</a></td>
    <td align="center"><a title="Award this picture 91 points" href="{RATE91}" rel="nofollow">91</a></td>
    <td align="center"><a title="Award this picture 92 points" href="{RATE92}" rel="nofollow">92</a></td>
    <td align="center"><a title="Award this picture 93 points" href="{RATE93}" rel="nofollow">93</a></td>
    <td align="center"><a title="Award this picture 94 points" href="{RATE94}" rel="nofollow">94</a></td>
    <td align="center"><a title="Award this picture 95 points" href="{RATE95}" rel="nofollow">95</a></td>
    <td align="center"><a title="Award this picture 96 points" href="{RATE96}" rel="nofollow">96</a></td>
    <td align="center"><a title="Award this picture 97 points" href="{RATE97}" rel="nofollow">97</a></td>
    <td align="center"><a title="Award this picture 98 points" href="{RATE98}" rel="nofollow">98</a></td>
    <td align="center"><a title="Award this picture 99 points" href="{RATE99}" rel="nofollow">99</a></td>
  </tr>
  <tr>
    <td align="center"><a title="Award this picture 100 points" href="{RATE100}" rel="nofollow">100</a></td>
  </tr>
</table>



and the themes.inc.php :

if (!function_exists('theme_html_rating_box')) {  //{THEMES}
function theme_html_rating_box()
{
    global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $THEME_DIR;
    global $template_image_rating, $lang_rate_pic;

    if (!(USER_CAN_RATE_PICTURES && $CURRENT_ALBUM_DATA['votes'] == 'YES')) return '';

    $votes = $CURRENT_PIC_DATA['votes'] ? sprintf($lang_rate_pic['rating'], round($CURRENT_PIC_DATA['pic_rating'] / 2000, 1), $CURRENT_PIC_DATA['votes']) : $lang_rate_pic['no_votes'];
    $pid = $CURRENT_PIC_DATA['pid'];

    if (defined('THEME_HAS_RATING_GRAPHICS')) {
        $location= $THEME_DIR;
    } else {
        $location= '';
    }

    $params = array('{TITLE}' => $lang_rate_pic['rate_this_pic'],
        '{VOTES}' => $votes,
        '{RATE0}' => "ratepic.php?pic=$pid&amp;rate=0",
        '{RATE1}' => "ratepic.php?pic=$pid&amp;rate=1",
        '{RATE2}' => "ratepic.php?pic=$pid&amp;rate=2",
        '{RATE3}' => "ratepic.php?pic=$pid&amp;rate=3",
        '{RATE4}' => "ratepic.php?pic=$pid&amp;rate=4",
        '{RATE5}' => "ratepic.php?pic=$pid&amp;rate=5",
        '{RATE6}' => "ratepic.php?pic=$pid&amp;rate=6",
        '{RATE8}' => "ratepic.php?pic=$pid&amp;rate=8",
        '{RATE9}' => "ratepic.php?pic=$pid&amp;rate=9",
        '{RATE10}' => "ratepic.php?pic=$pid&amp;rate=10",
        '{RATE11}' => "ratepic.php?pic=$pid&amp;rate=11",
        '{RATE12}' => "ratepic.php?pic=$pid&amp;rate=12",

.....
'{RATE96}' => "ratepic.php?pic=$pid&amp;rate=96",
'{RATE97}' => "ratepic.php?pic=$pid&amp;rate=97",
'{RATE98}' => "ratepic.php?pic=$pid&amp;rate=98",
'{RATE99}' => "ratepic.php?pic=$pid&amp;rate=99",
'{RATE100}' => "ratepic.php?pic=$pid&amp;rate=100",
        '{RUBBISH}' => $lang_rate_pic['rubbish'],
        '{POOR}' => $lang_rate_pic['poor'],
        '{FAIR}' => $lang_rate_pic['fair'],
        '{GOOD}' => $lang_rate_pic['good'],
        '{EXCELLENT}' => $lang_rate_pic['excellent'],
        '{GREAT}' => $lang_rate_pic['great'],
        '{GREATEST}' => $lang_rate_pic['greatest'],
        '{WIDTH}' => $CONFIG['picture_table_width'],
        '{LOCATION}' => $location,        //theme dir or default images directory
        );

    return template_eval($template_image_rating, $params);
}
}  //{THEMES}


and the ratepic.php :
from:

$rate = min($rate, 100);
$rate = max($rate, 0);


to:

$rate = min($rate, 100);
$rate = max($rate, 0);



One thing is : why the $new_rating = round(($row['votes'] * $row['pic_rating'] + $rate * 2000) / ($row['votes'] + 1)); in ratepic.php?

Joachim Müller

Quote from: morch on October 29, 2009, 09:07:12 AMand the themes.inc.php
that's wrong: never ever edit include/themes.inc.php, under no circumstances. Evereything that could be accomplished by editing that file can be accomplished as well be editing themes/yourtheme/theme.php !

morch

Ok - moved what I altered in themes.inc.php to theme.php, restored the original themes.inc.php and that works too.

Vielen Dank ;D