You are here

function fb_post_entity_page in Drupal for Facebook 7.4

1 string reference to 'fb_post_entity_page'
fb_post_menu in ./fb_post.module
Implements hook_menu().

File

./fb_post.module, line 63

Code

function fb_post_entity_page($type, $entity) {
  $token = fb_get_admin_token();
  if (!isset($entity->fb_post_graph) || !count($entity->fb_post_graph)) {
    $output['fb_post_status'] = array(
      '#markup' => t('Not posted to facebook.'),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    );
  }
  else {
    $output['fb_post_status'] = array(
      '#markup' => t('Posted to facebook %count times.', array(
        '%count' => count($entity->fb_post_graph),
      )),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    );

    /* How to generate this link????
       foreach ($entity->fb_post_graph as $row) {
         $url = "http://graph.facebook.com/" . $row->graph_id . '/link';
         $output['fb_post_posts'][$row->graph_id] = array(
           // @TODO - better markup.
           '#markup' => l($row->graph_id, $url, array(
                            //'query' => array('access_token' => $token))),
           '#prefix' => '<p>', '#suffix' => '</p>',
         );
       }
       */
  }

  // Provide a post to facebook link.
  if ($user_token = fb_user_token()) {
    $this_page = url("node/{$node->nid}", array(
      'absolute' => TRUE,
    ));
    $url = url("http://www.facebook.com/dialog/feed", array(
      'external' => TRUE,
      'query' => array(
        'display' => 'popup',
        'app_id' => $app['client_id'],
        'redirect_uri' => $this_page,
        'access_token' => $user_token,
      ),
    ));
    $output['fb_post_link'] = array(
      '#markup' => t('<a href="!url">Post to Facebook via your facebook account</a>.', array(
        '!url' => $url,
      )),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    );

    // @TODO - if user has posted, save to fb_post_graph table!
  }

  // Allow post using site-wide settings.
  $output['fb_post_form'] = drupal_get_form('fb_post_entity_publish_form', $entity);
  return $output;
}