1 (edited by KeyDog 2009-01-04 18:13)

Topic: Rating Script Extension Code

These are the three files that this rating extension has
(plus there is a folder "/stars/" with the images)
include/rate.php
rate.js
manifest.xml
(links lead to my forum - just so that not all the code is cluttering this post!)

I would appreciate anyone (dev, etc) taking a hard look at it -  as I can't get it to work yet.

Main trouble being:

1. uninstall section in manifest.xml  aswell as unsure about install manifest.xml

2. hooks are working for placing in header but only show "ratings" text, instead of showing the gif of stars rating

any feedback welcome
PS: if anyone can make this work for $ - just give me a price and satisfaction guarantee big_smile




working on a rating extension of posts/page and i need to integrate this ;
SQL statement

             CREATE TABLE `tableName` (
          `ip` varchar(15) NOT NULL,
          `rating` varchar(1) NOT NULL,
          `page` varchar(99) NOT NULL,
          PRIMARY KEY  (`ip`,`page`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

any pointers please?

EDIT: Changed Title.

Re: Rating Script Extension Code

Example using $forum_db functions.

    $schema = array(
        'FIELDS'        => array(
            'id'            => array(
                'datatype'        => 'SERIAL',
                'allow_null'    => false
            ),
            'cat_name'        => array(
                'datatype'        => 'VARCHAR(80)',
                'allow_null'    => false,
                'default'        => '\'New Category\''
            ),
            'disp_position'    => array(
                'datatype'        => 'INT(10)',
                'allow_null'    => false,
                'default'        => '0'
            )
        ),
        'PRIMARY KEY'    => array('id')
    );
    $forum_db->create_table('categories', $schema);

3 (edited by KeyDog 2008-12-19 01:31)

Re: Rating Script Extension Code

thanks; 
will i need to include this which is now named  include/constants.php somehow in manifest.xml

<?
define("DB_SERVER", "");
define("DB_USER", "");
define("DB_PASS", "");
define("DB_NAME", "");
define("DB_TABLE", "");

$dbhandle = mysql_connect(DB_SERVER,DB_USER,DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $dbhandle) or die(mysql_error());
?>

or is this information that can be called upon differently with a hook or something

Re: Rating Script Extension Code

No, you don't need that.

5 (edited by KeyDog 2008-12-19 23:20)

Re: Rating Script Extension Code

just to give you entire picture I need to do this:

I need to place

writeRate(identifier);

in either

item-subject

    of forum or in starting post of a forum post by a user/admin etc

imagine you have a list of topics and next to the item starter there is a rating of article

I'll be placing the this in manifest.xml

<hook id="hd_head">
      <![CDATA[
     $forum_head['ratings'] = '<script type="text/javascript" src="rate.js"></script>';
      ]]>
    </hook> 

to get the javascript.

for creating table I will use this 

$schema = array(
        'FIELDS'        => array(
            'id'            => array(
                'datatype'        => 'SERIAL',
                'allow_null'    => false
            ),
            'cat_name'        => array(
                'datatype'        => 'VARCHAR(80)',
                'allow_null'    => false,
                'default'        => '\'New Category\''
            ),
            'disp_position'    => array(
                'datatype'        => 'INT(10)',
                'allow_null'    => false,
                'default'        => '0'
            )
        ),
        'PRIMARY KEY'    => array('id')
    );
    $forum_db->create_table('categories', $schema);

from you smile
based on the following mysql statment

CREATE TABLE `tableName` (
          `ip` varchar(15) NOT NULL,
          `rating` varchar(1) NOT NULL,
          `page` varchar(99) NOT NULL,
          PRIMARY KEY  (`ip`,`page`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;




in original php I have this

<?
include("include/rate.php");
?>
above header

and this :
<?
writeRate(test);
?>
in body of rate.php

how should I implement this in the manifest.xml

the file include/rate.php looks like this:


$action = $_GET['a'];
if($action==1)
{
    rate();
}
if($action==2)
{
    reRate();
}

function rate()
{
    $star_value = $_GET['r'];
    $page       = $_GET['p'];
    $ip         = $_SERVER['REMOTE_ADDR'];
   
    //Add to database
    mysql_query("INSERT INTO `".DB_TABLE."` VALUES ('$ip','$star_value','$page')");
    $ref = $_SERVER['HTTP_REFERER'];
    header("Location: " .$ref);
}

function reRate()
{
    $star_value = $_GET['r'];
    $page       = $_GET['p'];
    $ip         = $_SERVER['REMOTE_ADDR'];
   
    //Add to database
    mysql_query("UPDATE `".DB_TABLE."` SET `rating` = '$star_value' WHERE `ip` = '$ip' AND `page` = '$page'");
    $ref = $_SERVER['HTTP_REFERER'];
    header("Location: " .$ref);
}

function writeRate($page)
{
    $ip = $_SERVER['REMOTE_ADDR'];
    $result = mysql_query("SELECT `ip` FROM `".DB_TABLE."` WHERE `ip` = '".$ip."' AND `page` = '$page'");
    $num_rows = mysql_num_rows($result);
    if($num_rows==1)
    {
        echo '<p>Your Rating: ';
        $result = mysql_query("SELECT `rating` FROM `".DB_TABLE."` WHERE `ip` = '".$ip."' AND `page` = '$page'");
        $rating = mysql_result($result, 0);
        if($rating == 1)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a>';
        }
        if($rating == 2)
and so on for each rating of 5

basically i want to make this into an extension....

the original script has
rate.php
rate.js
/include/rate.php
(and includes/constants.php where db info was placed)
/stars/  (gifs)

Re: Rating Script Extension Code

PS: this is what comes after 5th rating star line   
        }
        echo '<br>';
    }
    else
    {
        echo '<p>Your Rating: ';
        echo ' <a href="include/rate.php?p='.$page.'&r=1&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a>';
          echo '<br>';
    }
   
$result = mysql_query("SELECT `rating` FROM `".DB_TABLE."` WHERE `page` = '".$page."'");
        $num_rows = mysql_num_rows($result);
        $i=0;
        $star_value = 0;
        while($i<$num_rows)
        {
            $rating = mysql_result($result,$i);
            $star_value = $star_value + $rating;
            $i++;
        }
        if($star_value==0)
        {
            $avg_value = 0;
        }
        else
        {
            $avg_value = $star_value / $num_rows;
        }



//Assign Value
if ($avg_value <= 0  ){$rater_stars = "stars/00star.gif";}
if ($avg_value >= 0.5){$rater_stars = "stars/05star.gif";}
if ($avg_value >= 1  ){$rater_stars = "stars/1star.gif";}
if ($avg_value >= 1.5){$rater_stars = "stars/15star.gif";}
if ($avg_value >= 2  ){$rater_stars = "stars/2star.gif";}
if ($avg_value >= 2.5){$rater_stars = "stars/25star.gif";}
if ($avg_value >= 3  ){$rater_stars = "stars/3star.gif";}
if ($avg_value >= 3.5){$rater_stars = "stars/35star.gif";}
if ($avg_value >= 4  ){$rater_stars = "stars/4star.gif";}
if ($avg_value >= 4.5){$rater_stars = "stars/45star.gif";}
if ($avg_value >= 5  ){$rater_stars = "stars/5star.gif";}

    echo 'Avg Rating: <img src="'.$rater_stars.'" width="80" height="16" border="0" name="Rate"/>';
    echo '<br>';
    echo $num_rows." Ratings (Avg ".substr($avg_value,0,4).")";   
       

}
?>

7 (edited by KeyDog 2008-12-20 10:27)

Re: Rating Script Extension Code

I'm trying to find the hooks in functions.php
to place the  writeRate(identifier);    in the screenshots you can see below

Screenshot 1:
http://www.dumpt.com/img/files/pmu1agvhxstg0vk7ioa2_thumb.gif

see in proper size here

Screenshot 2:
http://www.dumpt.com/img/files/zeyx9wbpdvqyn0g91tgh_thumb.gif

see in proper size here

Any Input on that anyone? I'm not familiar with all these hooks so would be brilliant if a developer could say: hey you need to put it in XYZ for screenshot 2....

Re: Rating Script Extension Code

http://rapidshare.com/files/175113535/rating_script.rar   

here what I have untill now in manifest.xml , the rate.js   and screenshots aswell as the stars gifs...

any feedback on the xml please?

Re: Rating Script Extension Code

To add something next to each topic's title (Pic A), use hook 'vf_topic_loop_normal_topic_pre_item_title_merge' and

$forum_page['item_title']['link'] .= 'Your rating box thing';

To add something next to the post number, use hook 'vt_row_pre_post_ident_merge' and

$forum_page['post_ident']['num'] = 'Your rating box thing'.$forum_page['post_ident']['num'];

Now I'm back to playing Sim City 4 big_smile ... it's addicting wink

10 (edited by KeyDog 2008-12-20 14:00)

Re: Rating Script Extension Code

    <description>Rate posts as you know it from youtube</description>
    <author>KeyDog contributors La'me - Garciat - j.roszk</author>
    <minversion>1.3 Beta</minversion>
    <maxtestedon>1.3 Beta</maxtestedon>
    
    <hooks>
        <hook id="hd_head"><![CDATA[
        // To place the rate.js in header
             $forum_head['ratings'] = '<script type="text/javascript" src="rate.js"></script>';
        ]]>
            </hook>
        <hook id="vf_topic_loop_normal_topic_pre_item_title_merge"><![CDATA[
            // To add  to each topic's title (Screenshot 1)
            $forum_page['item_title']['link'] .= 'ratings';
    
        ]]>
        </hook>
        <hook id="vt_row_pre_post_ident_merge"><![CDATA[
            // To add  to the post number
            $forum_page['post_ident']['num'] = 'ratings'.$forum_page['post_ident']['num'];
    
        ]]>
        </hook> 
        <hook id="hd_head"><![CDATA[
            // Adding SQL statement / creating table
            $schema = array(
                'FIELDS'        => array(
                        'id'            => array(
                        'datatype'        => 'SERIAL',
                        'allow_null'    => false
                    ),
                    'cat_name'        => array(
                        'datatype'        => 'VARCHAR(80)',
                        'allow_null'    => false,
                        'default'        => '\'New Category\''
                    ),
                    'disp_position'    => array(
                        'datatype'        => 'INT(10)',
                        'allow_null'    => false,
                        'default'        => '0'
                    )
                ),
                'PRIMARY KEY'    => array('id')
            );
            $forum_db->create_table('categories', $schema);  
            ]]>
            <hook id="hd_head"><![CDATA[
            // not sure where this hook will go yet
$action = forum_htmlencode($_GET['a']);
if($action == 1)
{
    rate();
}
if($action == 2)
{
    reRate();
}

function rate()
{
    $star_value = forum_htmlencode($_GET['r']);
    $page       = forum_htmlencode($_GET['p']);
    $ip         = $_SERVER['REMOTE_ADDR'];
   
    //Add to database
    $query = array(
        'INSERT'    => 'ip, rating, page',
        'INTO'        => DB_TABLE,
        'VALUES'    => $ip.', '.$star_value.', '.$page
    );
    $forum_db->query_build($query) or error(__FILE__, __LINE__);
    $ref = $_SERVER['HTTP_REFERER'];
    redirect($ref, 'Redirecting, Please wait &hellip;');
}

function reRate()
{
    $star_value = forum_htmlencode($_GET['r']);
    $page       = forum_htmlencode($_GET['p']);
    $ip         = $_SERVER['REMOTE_ADDR'];
   
    //Add to database
    $query = array(
        'UPDATE'    => DB_TABLE,
        'SET'        => 'rating = '.$star_value,
        'WHERE'        => 'ip = '.$ip.' AND page = '.$page
    );
    $forum_db->query_build($query) or error(__FILE__, __LINE__);
    $ref = $_SERVER['HTTP_REFERER'];
    redirect($ref, 'Redirecting, Please wait &hellip;');
}

function writeRate($page)
{
    $ip = $_SERVER['REMOTE_ADDR'];
    $query = array(
        'SELECT'    => 'ip',
        'FROM'        => DB_TABLE,
        'WHERE'        => 'ip = '.$ip.' AND page = '.$page
    );
    $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
    $num_rows = $forum_db->num_rows($result);
    if($num_rows == 1)
    {
        echo '<p>Your Rating: ';
        $query = array(
            'SELECT'    => 'rating',
            'FROM'        => DB_TABLE,
            'WHERE'        => 'ip = '.$ip.' AND page = '.$page
        );
        $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
        $rating = $forum_db->result($result);
        if($rating == 1)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a>';
        }
        if($rating == 2)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a>';
        }
        if($rating == 3)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a>';
        }
        if($rating == 4)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a>';
        }
        if($rating == 5)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a>';
        }
        echo '<br>';
    }
    else
    {
        echo '<p>Your Rating: ';
        echo ' <a href="include/rate.php?p='.$page.'&r=1&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a>';
          echo '<br>';
    }
    
$result = mysql_query("SELECT `rating` FROM `".DB_TABLE."` WHERE `page` = '".$page."'");
        $num_rows = mysql_num_rows($result);
        $i=0;
        $star_value = 0;
        while($i<$num_rows)
        {
            $rating = mysql_result($result,$i);
            $star_value = $star_value + $rating;
            $i++;
        }
        if($star_value==0)
        {
            $avg_value = 0;
        }
        else
        {
            $avg_value = $star_value / $num_rows;
        }



//Assign Value
if ($avg_value <= 0  ){$rater_stars = "stars/00star.gif";}
if ($avg_value >= 0.5){$rater_stars = "stars/05star.gif";}
if ($avg_value >= 1  ){$rater_stars = "stars/1star.gif";}
if ($avg_value >= 1.5){$rater_stars = "stars/15star.gif";}
if ($avg_value >= 2  ){$rater_stars = "stars/2star.gif";}
if ($avg_value >= 2.5){$rater_stars = "stars/25star.gif";}
if ($avg_value >= 3  ){$rater_stars = "stars/3star.gif";}
if ($avg_value >= 3.5){$rater_stars = "stars/35star.gif";}
if ($avg_value >= 4  ){$rater_stars = "stars/4star.gif";}
if ($avg_value >= 4.5){$rater_stars = "stars/45star.gif";}
if ($avg_value >= 5  ){$rater_stars = "stars/5star.gif";}

    echo 'Avg Rating: <img src="'.$rater_stars.'" width="80" height="16" border="0" name="Rate"/>';
    echo '<br>';
    echo $num_rows." Ratings (Avg ".substr($avg_value,0,4).")";    
        
        $query = array(
            'SELECT'    => 'rating',
            'FROM'        => DB_TABLE,
            'WHERE'        => 'page = '.$page
        );
        $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);

        $num_rows = $forum_db->num_rows($result);
        $i = 0;
        $star_value = 0;
        while($i < $num_rows)
        {
            $rating = $forum_db->result($result,$i);
            $star_value = $star_value + $rating;
            $i++;
        }
        if($star_value == 0)
        {
            $avg_value = 0;
        }
        else
        {
            $avg_value = $star_value / $num_rows;
        }
}
      ]]>
    </hooks>
</extension>

just wondering the last and largest part of code - where do i hook that to

11

Re: Rating Script Extension Code

2 Questions:

// Adding SQL statement / creating table
            $schema = array(
                'FIELDS'        => array(
                        'id'            => array(
                        'datatype'        => 'SERIAL',
                        'allow_null'    => false
                    ),   

...... etc

// not sure where this hook will go yet
$action = forum_htmlencode($_GET['a']);
if($action == 1)
{
    rate();
}
if($action == 2)
{
    reRate();
}

etc......

Where Do I need to hook those ?

12

Re: Rating Script Extension Code

The first one on <install></install>:

<?xml version="1.0" encoding="utf-8"?>
<extension engine="1.0">
    <id>sitemap</id>
    <title>Sitemap Generator</title>
    <version>1.2.4</version>
    <description>Allows the forum to generate a standard-complying sitemap.</description>
    <author>Garciat</author>
    <minversion>1.3</minversion>
    <maxtestedon>1.3</maxtestedon>
    
    <install>
        <![CDATA[

        ]]>
    </install>

...

</extension>

13 (edited by KeyDog 2008-12-21 03:11)

Re: Rating Script Extension Code

<extension engine="1.0">
    <id>rating_script</id>
    <title>Rating Script</title>
    <version>0.1.0</version>
    <description>Rate posts as you know it from youtube</description>
    <author>KeyDog contributors La'me - Garciat - j.roszk</author>
    <minversion>1.3 Beta</minversion>
    <maxtestedon>1.3 Beta</maxtestedon>
    <install>
     <![CDATA[
                // Adding SQL statement / creating table /installation code
            $schema = array(
                'FIELDS'        => array(
                        'id'            => array(
                        'datatype'        => 'SERIAL',
                        'allow_null'    => false
                    ),
                    'cat_name'        => array(
                        'datatype'        => 'VARCHAR(80)',
                        'allow_null'    => false,
                        'default'        => '\'New Category\''
                    ),
                    'disp_position'    => array(
                        'datatype'        => 'INT(10)',
                        'allow_null'    => false,
                        'default'        => '0'
                    )
                ),
                'PRIMARY KEY'    => array('id')
            );
            $forum_db->create_table('categories', $schema);        
        ]]>  
    </install>
   
            <uninstall><![CDATA[
        // Uninstallation code
            $query = array(
            'DELETE'    => '??????',
            'WHERE'        => '????? in (\'New Category\'')',
            );
            $forum_db->create_table('categories', $schema);
    ]]></uninstall>
    <hooks>
        <hook id="hd_head"><![CDATA[
        // To place the rate.js in header
             $forum_head['ratings'] = '<script type="text/javascript" src="rate.js"></script>';
        ]]>
           </hook>
        <hook id="vf_topic_loop_normal_topic_pre_item_title_merge"><![CDATA[
            // To add  to each topic's title (Screenshot 1)
            $forum_page['item_title']['link'] .= 'ratings';
    
        ]]>
        </hook>
        <hook id="vt_row_pre_post_ident_merge"><![CDATA[
            // To add  to the post number
            $forum_page['post_ident']['num'] = 'ratings'.$forum_page['post_ident']['num'];
    
        ]]>
        </hook> 
        <hook id="vf_start"><![CDATA[
        // Include tbe include/rate.php from extension directory
            require $ext_info['path'].'/include/rate.php';
          ]]>
        </hook>    
    </hooks>
</extension>

this is my xml.manifest now

how do i do the uninstall????
thx for all the inputs.

14 (edited by KeyDog 2008-12-21 04:03)

Re: Rating Script Extension Code

this is include/rate.php
but once i install everything it tells me  :

Notice: Undefined index: a
include/rate.php on line 3
$action = forum_htmlencode($_GET['a']);
do you think this would help solves issue; sanitizing?

Do not ever use forum_htmlencode on input. Do not ever use it to sanitize a string for use in the database.
forum_htmlencode should be used on output only, to prevent XSS. To sanitize a string for use in the database, use $db->escape.

  <---- how do I implement this in my example here please? anyone....

thx

<?

$action = forum_htmlencode($_GET['a']);
if($action == 1)
{
    rate();
}
if($action == 2)
{
    reRate();
}

function rate()
{
    $star_value = forum_htmlencode($_GET['r']);
    $page       = forum_htmlencode($_GET['p']);
    $ip         = $_SERVER['REMOTE_ADDR'];
   
    //Add to database
    $query = array(
        'INSERT'    => 'ip, rating, page',
        'INTO'        => DB_TABLE,
        'VALUES'    => $ip.', '.$star_value.', '.$page
    );
    $forum_db->query_build($query) or error(__FILE__, __LINE__);
    $ref = $_SERVER['HTTP_REFERER'];
    redirect($ref, 'Redirecting, Please wait &hellip;');
}

function reRate()
{
    $star_value = forum_htmlencode($_GET['r']);
    $page       = forum_htmlencode($_GET['p']);
    $ip         = $_SERVER['REMOTE_ADDR'];
   
    //Add to database
    $query = array(
        'UPDATE'    => DB_TABLE,
        'SET'        => 'rating = '.$star_value,
        'WHERE'        => 'ip = '.$ip.' AND page = '.$page
    );
    $forum_db->query_build($query) or error(__FILE__, __LINE__);
    $ref = $_SERVER['HTTP_REFERER'];
    redirect($ref, 'Redirecting, Please wait &hellip;');
}

function writeRate($page)
{
    $ip = $_SERVER['REMOTE_ADDR'];
    $query = array(
        'SELECT'    => 'ip',
        'FROM'        => DB_TABLE,
        'WHERE'        => 'ip = '.$ip.' AND page = '.$page
    );
    $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
    $num_rows = $forum_db->num_rows($result);
    if($num_rows == 1)
    {
        echo '<p>Your Rating: ';
        $query = array(
            'SELECT'    => 'rating',
            'FROM'        => DB_TABLE,
            'WHERE'        => 'ip = '.$ip.' AND page = '.$page
        );
        $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
        $rating = $forum_db->result($result);
        if($rating == 1)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a>';
        }
        if($rating == 2)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a>';
        }
        if($rating == 3)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a>';
        }
        if($rating == 4)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a>';
        }
        if($rating == 5)
        {
            echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a>';
        }
        echo '<br>';
    }
    else
    {
        echo '<p>Your Rating: ';
        echo ' <a href="include/rate.php?p='.$page.'&r=1&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a>';
          echo '<br>';
    }
    

        $query = array(
            'SELECT'    => 'rating',
            'FROM'        => DB_TABLE,
            'WHERE'        => 'page = '.$page
        );
        $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);

        $num_rows = $forum_db->num_rows($result);
        $i = 0;
        $star_value = 0;
        while($i < $num_rows)
        {
            $rating = $forum_db->result($result,$i);
            $star_value = $star_value + $rating;
            $i++;
        }
        if($star_value == 0)
        {
            $avg_value = 0;
        }
        else
        {
            $avg_value = $star_value / $num_rows;
        }



//Assign Value
if ($avg_value <= 0  ){$rater_stars = "stars/00star.gif";}
if ($avg_value >= 0.5){$rater_stars = "stars/05star.gif";}
if ($avg_value >= 1  ){$rater_stars = "stars/1star.gif";}
if ($avg_value >= 1.5){$rater_stars = "stars/15star.gif";}
if ($avg_value >= 2  ){$rater_stars = "stars/2star.gif";}
if ($avg_value >= 2.5){$rater_stars = "stars/25star.gif";}
if ($avg_value >= 3  ){$rater_stars = "stars/3star.gif";}
if ($avg_value >= 3.5){$rater_stars = "stars/35star.gif";}
if ($avg_value >= 4  ){$rater_stars = "stars/4star.gif";}
if ($avg_value >= 4.5){$rater_stars = "stars/45star.gif";}
if ($avg_value >= 5  ){$rater_stars = "stars/5star.gif";}

    echo 'Avg Rating: <img src="'.$rater_stars.'" width="80" height="16" border="0" name="Rate"/>';
    echo '<br>';
    echo $num_rows." Ratings (Avg ".substr($avg_value,0,4).")";    
        
}

?>

15 (edited by KeyDog 2008-12-21 15:41)

Re: Rating Script Extension Code

$forum_head['ratings'] = '<script type="text/javascript" src="rate.js"></script>';

should be:

$forum_head['ratings'] = '<script type="text/javascript" src="'.$ext_info['url'].'/rate.js"></script>';

and:

$action = forum_htmlencode($_GET['a']);

should be:

$action = isset($_GET['action']) ? intval($_GET['action']) : '';

made the above changes

most recent rating_script version here:

not working yet ... but no errors anymore

remaining issue:

1. after changing "'.$ext_info['url'].'/ to go before all the stars etc...
it just places the TEXT rating in the location where my stars should be - any idea what that could be about?

2. uninstall. how do i write that correctly?

thanks

16

Re: Rating Script Extension Code

remaining issue

probably really stupid question right, but
it places the TEXT:  rating    where my stars should be at the moment!

plus:
the uninstall - what does that need to look like?
install is fine. but UNinstall prob.

i guess the stars need ".$ext_info['url'].'/  down below aswell in the .js big_smile ?

  
function Swap1(page){
    document[""+page+"one"].src = "stars/star.gif";
    return true;
  }
  function Swap2(page){
    document[""+page+"one"].src = "stars/star.gif";
    document[""+page+"two"].src = "stars/star.gif";
    return true;

and last question for mo:
this is in include/rate.php

 
//Assign Value
if ($avg_value <= 0  ){$rater_stars = "stars/00star.gif";}
if ($avg_value >= 0.5){$rater_stars = "stars/05star.gif";}
if ($avg_value >= 1  ){$rater_stars = "stars/1star.gif";}
if ($avg_value >= 1.5){$rater_stars = "stars/15star.gif";}
if ($avg_value >= 2  ){$rater_stars = "stars/2star.gif";}
if ($avg_value >= 2.5){$rater_stars = "stars/25star.gif";}
if ($avg_value >= 3  ){$rater_stars = "stars/3star.gif";}
if ($avg_value >= 3.5){$rater_stars = "stars/35star.gif";}
if ($avg_value >= 4  ){$rater_stars = "stars/4star.gif";}
if ($avg_value >= 4.5){$rater_stars = "stars/45star.gif";}
if ($avg_value >= 5  ){$rater_stars = "stars/5star.gif";}

    echo 'Avg Rating: <img src="'.$rater_stars.'" width="80" height="16" border="0" name="Rate"/>';
    echo '<br>';
    echo $num_rows." Ratings (Avg ".substr($avg_value,0,4).")";    

what do i need to change the img src to if at all ? example?
thank you

17 (edited by KeyDog 2008-12-22 13:39)

Re: Rating Script Extension Code

http://rapidshare.com/files/175762519/rating_script.rar   <-- latest code I'm working on

this as I said has following prob:
1. uninstall - don't know what value I need to put in
2. a) $rater_stars    source - not sure what and if that needs to be changed

//Assign Value
if ($avg_value <= 0  ){$rater_stars = "stars/00star.gif";}
//Assign Value
if ($avg_value <= 0  ){$rater_stars = ".$ext_info['url'].'/stars/00star.gif";}

2. b) in the .js   do I need to change 

document[""+page+"one"].src = "stars/star.gif";
document[""+page+"one"].src = ".$ext_info['url'].'/stars/star.gif";

if it is right like this ^ 
http://rapidshare.com/files/175768778/r … t_beta.rar  <-- this will be corrected version

3. issue of forum_htmlencode  / $db->escape   - need more info on sanitizing

thx all !

18

Re: Rating Script Extension Code

1.- On the uninstall part, you have to undo everything you did on the install part. So, you have to drop the table you created.

2 b).- I don't think you can use PHP variables ($ext_info) on JS...

3.- $forum_db->escape?

19 (edited by KeyDog 2008-12-22 14:56)

Re: Rating Script Extension Code

thx!
so re 2b)  - i need to change

document[""+page+"one"].src = ".$ext_info['url'].'/stars/star.gif";
document[""+page+"one"].src = "extensions/rating_script/stars/star.gif";

to get it working?
in the rate.js

20

Re: Rating Script Extension Code

You'd have to figure out how to get the base URL... maybe using a .php file with your JS script in it and adding this to the top:

<?php
header("Content-Type: text/javascript");
?>

Then, when you need the JS file, you do something like:

<script type="text/javascript" src="url_to_php_file.php?base_url=<?php echo urlencode($base_url) ?>"></script>

Finally:

document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";

Hope that works...

21 (edited by KeyDog 2008-12-22 21:35)

Re: Rating Script Extension Code

my rate.js : (with "Finally:" change from you)

function Swap1(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap2(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap3(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap4(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap5(page){
   document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    return true;
  }
  function SwapBack(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackOne(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackTwo(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackThree(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackFour(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackFive(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    return true;
  }

Then, when you need the JS file, you do something like:

<script type="text/javascript" src="url_to_php_file.php?base_url=<?php echo urlencode($base_url) ?>"></script>

not sure what to do with that....

with your JS script in it

you mean the above code rate.js in "url_to_php_file.php" ; Q : how does it have to be "in it" ? - sorry not quite getting it yet big_smile thanks for your patience. my intentions are good smile

22 (edited by User33 2008-12-22 23:50)

Re: Rating Script Extension Code

Sorry I could explain myself better...

Basically, all you need is:

<?php
header("Content-Type: text/javascript");
?>
var base_url = '<?php echo urldecode($_GET['base_url']) ?>';

// place your javascript code here
//when you need the base URL, just do something like: base_url.'extensions/something/star.png';

As you can see, we're using PHP to set the MIME type to javascript so browsers recognize it as such.

So, to get the whole $_GET thing working, we need to replace your current script call with:

<script type="text/javascript" src="url/to/extension/javascript.php?base_url=<?php echo urlencode($base_url) ?>"></script>

That's the best I can do to explain it... if you don't get it, think harder?

23 (edited by KeyDog 2008-12-24 10:37)

Re: Rating Script Extension Code

So this is what I'd put in rating_script extension  called  rate.php   

<?php
header("Content-Type: text/javascript");
?>
var base_url = '<?php echo urldecode($_GET['base_url']) ?>';

function Swap1(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap2(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap3(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap4(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap5(page){
   document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/star.gif";
    return true;
  }
  function SwapBack(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackOne(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackTwo(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackThree(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackFour(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackFive(page){
    document[""+page+"one"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"four"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"five"].src = "<?php echo urldecode($_GET['base_url']) ?>extensions/rating_script/stars/starCurrent.gif";
    return true;
  }

Did you mean in this (above) new file rating_script/rate.php I need to modify according to this:

//when you need the base URL, just do something like: base_url.'extensions/something/star.png';

or

when I need it in other files   (rating_script/include/rate.php  ...  rating_script/manifest.xml)


THANKS. MERRY XMAS AND ALL THAT big_smile

24

Re: Rating Script Extension Code

Yes, that should work, but with

var base_url = '<?php echo urldecode($_GET['base_url']) ?>';

You already have the variable inside Javascript, so you could insted use:

base_url."extensions/rating_script/stars/star.gif";

, but the way you're doing it should work, I guess.

25 (edited by KeyDog 2008-12-24 14:44)

Re: Rating Script Extension Code

sure, your one makes much more sense. just code for nothing otherwise. double.

<?php
header("Content-Type: text/javascript");
?>
var base_url = '<?php echo urldecode($_GET['base_url']) ?>';

function Swap1(page){
    document[""+page+"one"].src = base_url."extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap2(page){
    document[""+page+"one"].src = base_url."extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = base_url."extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap3(page){
    document[""+page+"one"].src = base_url."extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = base_url."extensions/rating_script/stars/star.gif";
    document[""+page+"three"].src = base_url."extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap4(page){
    document[""+page+"one"].src = base_url."extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = base_url."extensions/rating_script/stars/star.gif";
    document[""+page+"three"].src = base_url."extensions/rating_script/stars/star.gif";
    document[""+page+"four"].src = base_url."extensions/rating_script/stars/star.gif";
    return true;
  }
  function Swap5(page){
   document[""+page+"one"].src = base_url."extensions/rating_script/stars/star.gif";
    document[""+page+"two"].src = base_url."extensions/rating_script/stars/star.gif";
    document[""+page+"three"].src = base_url."extensions/rating_script/stars/star.gif";
    document[""+page+"four"].src = base_url."extensions/rating_script/stars/star.gif";
    document[""+page+"five"].src = base_url."extensions/rating_script/stars/star.gif";
    return true;
  }
  function SwapBack(page){
    document[""+page+"one"].src = base_url."extensions/rating_script/stars/empty.gif";
    document[""+page+"two"].src = base_url."extensions/rating_script/stars/empty.gif";
    document[""+page+"three"].src = base_url."extensions/rating_script/stars/empty.gif";
    document[""+page+"four"].src = base_url."extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = base_url."extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackOne(page){
    document[""+page+"one"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = base_url."extensions/rating_script/stars/empty.gif";
    document[""+page+"three"].src = base_url."extensions/rating_script/stars/empty.gif";
    document[""+page+"four"].src = base_url."extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = base_url."extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackTwo(page){
    document[""+page+"one"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = base_url."extensions/rating_script/stars/empty.gif";
    document[""+page+"four"].src = base_url."extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = base_url."extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackThree(page){
    document[""+page+"one"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"four"].src = base_url."extensions/rating_script/stars/empty.gif";
    document[""+page+"five"].src = base_url."extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackFour(page){
    document[""+page+"one"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"four"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"five"].src = base_url."extensions/rating_script/stars/empty.gif";
    return true;
  }
  function SwapBackFive(page){
    document[""+page+"one"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"two"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"three"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"four"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    document[""+page+"five"].src = base_url."extensions/rating_script/stars/starCurrent.gif";
    return true;
  }