Skip to content

Instantly share code, notes, and snippets.

@mmohiudd
Created May 28, 2012 23:07
Show Gist options
  • Save mmohiudd/2821575 to your computer and use it in GitHub Desktop.
Save mmohiudd/2821575 to your computer and use it in GitHub Desktop.
kohana before for open grabp
public function before(){
parent::before();
// this block provides header information for facebook send message popup
if( preg_match('/facebook/', $_SERVER['HTTP_USER_AGENT'])) {
$facebook_config = kohana::$config->load('facebook');
$share = $facebook_config['share'][$this->lang];
$item_id = $this->request->query('id');
$media = ORM::factory('Media', $item_id)->as_array();
$meta['type'] = "website";
$meta['title'] = $share['caption'];
$meta['image'] = url::site() . "assets/img/sb_logo.jpg";
if( $media['type'] == 'image' ) {
$meta['image'] = url::site() . "/media/uploads/images/approved/" . $item_id . ".jpg";
} else if( $media['type'] == 'video' ) {
$meta['image'] = url::site() . "/media/uploads/images/bumper/" . $item_id . ".jpg";
}
$meta['description'] = $share['description'];
$meta['url'] = url::site() . "share/?id=" . $item_id;
echo '<meta property="fb:app_id" content="' . $facebook_config['app_id'] .'"/>' . "\n";
echo '<meta property="og:type" content="' . $meta['type'] . '" />' . "\n";
echo '<meta property="og:title" content="' . $meta['title'] . '"/>' . "\n";
echo '<meta property="og:image" content="' . $meta['image'] . '"/>' . "\n";
echo '<meta property="og:description" content="' . $meta['description'] . '"/>' . "\n";
echo '<meta property="og:url" content="' . $meta['url'] . '"/>' . "\n";
die();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment