Inserting fivestar widget in an external php file

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
RickyS's picture

Hello,

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:

<?php
//require the bootstrap include
require_once 'includes/bootstrap.inc';

//Load Drupal
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// fivestar_add_css();
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']))
{
$node = new stdClass();
    $node->is_new=1;
    $node->title = "comment_rating node".rand();
  $node->body = "";
$node->type = "comments_ratings";
$node->uid = 1;
$node->teaser = "";
   $node->filter = 1;
  $node->status = 1;
  $node->comment = 2;
$node->created = time();
    $node->changed = time();
    $node->field_problem[0]['value'] = $string;
   node_save($node);

$query2 = "SELECT ctcr.nid FROM content_type_comments_ratings AS ctcr WHERE ctcr.field_problem_value = '".$string."'";
   $result2=db_query($query2);
    $row2 = db_fetch_array($result2);
  if(isset($row2['nid']))
  {
      $nid = $row2['nid'];
     node_load(FALSE, NULL, TRUE);
      $fivestar = node_load($nid, NULL, TRUE);
       if (function_exists('fivestar_widget_form')) print fivestar_widget_form($fivestar);
  }
  else echo "error: no rating found";
}
else
{
$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);
}
/*
$path = drupal_get_path('module','fivestar');
drupal_add_js($path.'/js/fivestar.js','inline');
*/

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.

Voting Systems

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week