Q:

Drupal: Inserting fivestar widget in an external php file

I have been trying to load fivestar module and show the rating widget of the selected node in an external php file. I have gotten the rating widget displayed on the page but it only displays degraded version of the widget (non-JavaScript, dropdown widget and "Rate" button) I looked into the source code of the page but the javascript for fivestar module was not loaded. I have tried to load javascript using following functions but had no luck:
fivestar_add_js();
$path = drupal_get_path('module','fivestar');
drupal_add_js($path.'/js/fivestar.js', 'inline', 'footer');
The following is the code in the php file:
    //require the bootstrap include
    require_once 'includes/bootstrap.inc';

    //Load Drupal
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

    fivestar_add_css();

    // I have used one of the following two functions one at a time to test.
    fivestar_add_js();
    $path = drupal_get_path('module','fivestar');
    drupal_add_js($path.'/js/fivestar.js', 'inline', 'footer');

    $book = $_GET["book"];
    $chap = $_GET["chap"];
    $prob = $_GET["prob"];

    $string = $book.'/'.$chap.'/'.$prob;
    $query = "SELECT ctcr.nid FROM content_type_comments_ratings AS ctcr WHERE ctcr.field_problem_value = '".$string."'";
    $result=db_query($query);
    $row = db_fetch_array($result);
    if(isset($row['nid']))
    {
        $nid = $row['nid'];
        node_load(FALSE, NULL, TRUE);
        $fivestar = node_load($nid, NULL, TRUE);

        if (function_exists('fivestar_widget_form')) print fivestar_widget_form($fivestar);
    }

If you could give me a hint or direct me to some reading on the web, I would appreciate it. Thank you very much in advance.

A:

By doing all this on an 'external' page/file, you circumvent the Drupal theming system - drupal_add_js() (and fivestar_add_js(), as it is just using that in the end) do not output the script tags themselves, but simply ensure that they will be included in the $scripts variable in page.tpl.php, which is then responsible to print that variables content. As you do not go through the page template, you get no script tags.
You could do a print drupal_get_js(); in your external file to output the scripts added via drupal_add_js() as a quick fix, but note that this will output all the default drupal js files as well, which might be more than you need (but might as well contain other scripts needed by fivestar, e.g. jquery). Alternatively, you'll have to create the needed script tags yourself.
As for hints on what to read, it is difficult to point you to something particular, but you might want to read up on the theming system in general.

