public function show($type, $subtype, $slug) { $post = $this->posts->findSeoble($slug); $t = $this->posts->findSeoble($type)->subtypes->lists('id')->toarray(); $posts = $this->posts->orderBy('post', 'einddatum', 'desc')->where('subtype_id', '=', $post->subtype_id)->whereNotIn('id', [$post->id])->get(); $previous = $this->posts->orderBy('post', 'einddatum', 'desc')->whereIn('subtype_id', $t)->where('id', '<', $post->id)->first(); $next = $this->posts->orderBy('post', 'einddatum', 'asc')->whereIn('subtype_id', $t)->where('id', '>', $post->id)->first(); if (\Request::ajax()) { return response()->json(['url' => \Request::url(), 'title' => 'Portfolio | Jonas Vanderhaegen', 'path' => \Request::path(), 'view' => view('pages.posts.' . $type . '.show', compact('post', 'previous', 'next', 'posts'))->render()]); } $og = new \OpenGraph(true); $og->title($post->seo->first()->title . ' | ' . $type . ' | ' . $subtype . ' | Jonas Vanderhaegen')->type('article')->description($post->seo->first()->description)->url()->locale('nl_BE')->siteName('Jonas Vanderhaegen'); $og->article(['author' => 'Jonas Vanderhaegen', 'published_time' => $post->created_at->format('Y-m-d H:m:s'), 'modified_time' => $post->updated_at->format('Y-m-d H:m:s'), 'section' => $post->subtype->type->seo->first()->title]); $og->image('images/portfolio/' . $post->seo->first()->slug . '/1.jpg', ['width' => 720, 'height' => 400]); return view('pages.posts.' . $type . '.show', compact('post', 'previous', 'next', 'posts', 'og')); }
/** * Convert a single URL, assumes $url has been verified to be * a real URL * * @param string $url */ public function convertUrl($url) { $oembed = Oembed::get_oembed_from_url($url, false, $this->oembedOptions); if ($oembed) { return array('Title' => '', 'Content' => $oembed->forTemplate()); } $graph = OpenGraph::fetch($url); if ($graph) { foreach ($graph as $key => $value) { $data[$key] = Varchar::create_field('Varchar', $value); } if (isset($data['url'])) { return array('Title' => $graph->Title, 'Content' => MicroPost::create()->customise($data)->renderWith('OpenGraphPost')); } } // get the post and take its <title> tag at the very least $service = new RestfulService($url); $response = $service->request(); if ($response && $response->getStatusCode() == 200) { if (preg_match('/<title>(.*?)<\\/title>/is', $response->getBody(), $matches)) { $title = Convert::raw2xml(trim($matches[1])); return array('Title' => $title, 'Content' => "<a href='{$url}'>{$title}</a>"); } } }
protected function getConfigurableField($dbField, $configField) { $value = OpenGraph::get_config($configField); if ($value == 'SiteConfig') { return $this->owner->getField($dbField); } return $value; }
/** * @return string */ protected function getAppID() { if (class_exists('OpenGraph')) { return OpenGraph::get_config('application_id'); } else { return Config::inst()->get('FBLikeButtonExtension', 'application_id'); } }
public function testPopulateWithPlace() { $point = new Point(); $point->setLat('-23.59243454'); $point->setLng('-46.68677054'); $city = new City(); $city->setCountry('BR'); $city->setState('SP'); $city->setName('São Paulo'); $category = new Category(); $category->setId('123'); $category->setName('Empresas de Internet'); $address = new Address(); $address->setStreet("Rua Funchal"); $address->setNumber(129); $address->setComplement('6o andar'); $address->setCity($city); $place = new Place(); $place->setId("M25GJ288"); $place->setName("Apontador.com - São Paulo"); $place->setDescription("Líder em geolocalização no Brasil e uma das 250 maiores empresas de internet do mundo, segundo o AlwaysOn, o Apontador (www.apontador.com) desenvolve e oferece serviços e ferramentas de busca e localização para facilitar o dia a dia dos usuários, além de mostrar a opinião do público para os locais cadastrados em seus sites. Com mais de 10 milhões de visitantes mensais, a empresa inclui o site líder em busca local Apontador (www.apontador.com.br) e o de mapas e rotas MapLink (www.maplink.com.br)."); $place->setIconUrl("http://localphoto.s3.amazonaws.com/C40372534F143O1437_9896391605729015_l.jpg"); $place->setPoint($point); $place->setCategory($category); $place->setAddress($address); $this->og->populate($place); $rootUrl = \ROOT_URL; $testMeta = <<<META \t<meta property="og:title" content="Apontador.com - São Paulo"/> \t<meta property="og:description" content="Líder em geolocalização no Brasil e uma das 250 maiores empresas de internet do mundo, segundo o AlwaysOn, o Apontador (www.apontador.com) desenvolve e oferece serviços e ferramentas de busca e localização para facilitar o dia a dia dos usuários, além de mostrar a opinião do público para os locais cadastrados em seus sites. Com mais de 10 milhões de visitantes mensais, a empresa inclui o site líder em busca local Apontador (www.apontador.com.br) e o de mapas e rotas MapLink (www.maplink.com.br)."/> \t<meta property="og:image" content="http://maplink.com.br/widget?v=4.1&lat=-23.59243454&lng=-46.68677054"/> \t<meta property="og:url" content="{$rootUrl}sp/s-o-paulo/empresas-de-internet/apontador-com-s-o-paulo/M25GJ288.html"/> \t<meta property="og:street-address" content="Rua Funchal, 129"/> \t<meta property="og:locality" content="São Paulo"/> \t<meta property="og:region" content="SP"/> \t<meta property="og:country-name" content="Brasil"/> \t<meta property="og:latitude" content="-23.59243454"/> \t<meta property="og:longitude" content="-46.68677054"/> \t<meta property="og:type" content="company"/> META; $this->assertEquals($testMeta, $this->og->getMeta()); $testArray = array('title' => 'Apontador.com - São Paulo', 'description' => 'Líder em geolocalização no Brasil e uma das 250 maiores empresas de internet do mundo, segundo o AlwaysOn, o Apontador (www.apontador.com) desenvolve e oferece serviços e ferramentas de busca e localização para facilitar o dia a dia dos usuários, além de mostrar a opinião do público para os locais cadastrados em seus sites. Com mais de 10 milhões de visitantes mensais, a empresa inclui o site líder em busca local Apontador (www.apontador.com.br) e o de mapas e rotas MapLink (www.maplink.com.br).', 'image' => 'http://maplink.apontador.com.br/widget?v=4.1&lat=-23.59243454&lng=-46.68677054', 'url' => ROOT_URL . 'sp/s-o-paulo/empresas-de-internet/apontador-com-s-o-paulo/M25GJ288.html', 'street-address' => 'Rua Funchal, 129', 'locality' => 'São Paulo', 'region' => 'SP', 'country-name' => 'Brasil', 'latitude' => '-23.59243454', 'longitude' => '-46.68677054', 'type' => 'company'); $this->assertEquals($testArray, $this->og->getArray()); }
public static function getOpenGraphData($url) { $returnValues = array(); //obtengo los datos del enlace con su imagen titulo y descripcion haaa y la url $graph = OpenGraph::fetch($url); foreach ($graph as $key => $value) { switch ($key) { case 'title': $returnValues['title'] = $value; break; case 'description': $returnValues['description'] = $value; break; case 'site_name': $returnValues['siteName'] = $value; break; case 'image': $returnValues['image'] = $value; break; } } //Checking video link if youtube or vimeo $host = parse_url($url, PHP_URL_HOST); if ($host == 'vimeo.com') { $path = parse_url($url, PHP_URL_PATH); $clip_id = substr($path, 1); $returnValues['videoUrl'] = 'http://vimeo.com/moogaloop.swf?clip_id=' . $clip_id; } if ($host == 'www.youtube.com') { $query = parse_url($url, PHP_URL_QUERY); $v = explode("=", $query); $returnValues['videoUrl'] = 'http://www.youtube.com/v/' . $v[1] . '?version=3&autohide=1'; } if ($host == 'youtu.be') { $path = parse_url($url, PHP_URL_PATH); $returnValues['videoUrl'] = 'http://www.youtube.com/v' . $path . '?version=3&autohide=1'; } //veo si alguno de los campos esta vacio y mando la funcion con curl if (isset($returnValues['title']) && isset($returnValues['description']) && isset($returnValues['image']) && isset($returnValues['siteName'])) { return $returnValues; } $arr = OpenGraph::wget($url); if (!isset($returnValues['title'])) { $returnValues['title'] = $arr['title']; } if (!isset($returnValues['description'])) { $returnValues['description'] = $arr['description']; } if (!isset($returnValues['image'])) { $returnValues['image'] = $arr['og:image']; } if (!isset($returnValues['images'])) { $returnValues['images'] = $arr['images'][0]; } return $returnValues; }
/** * @param \Zend\Uri\Uri $uri */ public function parse(Uri $uri) { $this->url = $uri->toString(); $html = \OpenGraph::fetch($uri->toString()); // open graph $this->id = basename($uri->getPath()); $this->title = $html->title; $this->description = $html->description; $this->image = urlencode($html->image); }
public function testPopulateWithPlace() { $point = new Point(); $point->setLat('-23.59243454'); $point->setLng('-46.68677054'); $city = new City(); $city->setCountry('BR'); $city->setState('SP'); $city->setName('São Paulo'); $category = new Category(); $category->setId('067'); $category->setName('Restaurante'); $address = new Address(); $address->setStreet("R. Min. Jesuino Cardoso"); $address->setNumber(473); $address->setCity($city); $place = new Place(); $place->setId("UCV34B2P"); $place->setName("Uziel Restaurante"); $place->setDescription("Se você procura um restaurante com variedade, qualidade com preço justo você encontra no Uziel restaurante!O preço do kilo é R\$ 26,90, mas você paga no máximo R\$ 15,90 por pesagem de refeições (excluindo sobremesas, bebidas e doces). Acima de 500 gramas você ainda ganha um refrescoUm bom vinho, gelatina e cafezinho são por nossa conta.Se precisar de internet você pode contar com nossa rede Wi-Fi.Nosso cardápio diário possui 5 tipos de carne todos os dias, feijoada completa e separada (feijão e carnes) às quartas, 6 tipos de massa nas quintas e 4 tipos de pizzas nassextas, além de opções de peixes todas as terças e sextas.Oferecemos convênio com descontos progressivos para empresas e um bolo com o sabor a escolha do aniversariante, caso agende com antecedência e traga mais de 10 pessoas para almoçar no seu aniversário.Aceitamos todos os cartões de crédito e vales refeição.Você pode receber nosso cardápio atualizado diariamente pelo twitter http://twitter.com/uzielrestaurant"); $place->setIconUrl("http://maplink.com.br/widget?v=4.1&lat=-23.5926083&lng=-46.6818329"); $place->setPoint($point); $place->setCategory($category); $place->setAddress($address); $this->abm->populate($place); $rootUrl = \ROOT_URL; $testMeta = <<<META \t<meta property="restaurant:title" content="Uziel Restaurante"/> \t<meta property="restaurant:description" content="Se você procura um restaurante com variedade, qualidade com preço justo você encontra no Uziel restaurante!O preço do kilo é R\$ 26,90, mas você paga no máximo R\$ 15,90 por pesagem de refeições (excluindo sobremesas, bebidas e doces). Acima de 500 gramas você ainda ganha um refrescoUm bom vinho, gelatina e cafezinho são por nossa conta.Se precisar de internet você pode contar com nossa rede Wi-Fi.Nosso cardápio diário possui 5 tipos de carne todos os dias, feijoada completa e separada (feijão e carnes) às quartas, 6 tipos de massa nas quintas e 4 tipos de pizzas nassextas, além de opções de peixes todas as terças e sextas.Oferecemos convênio com descontos progressivos para empresas e um bolo com o sabor a escolha do aniversariante, caso agende com antecedência e traga mais de 10 pessoas para almoçar no seu aniversário.Aceitamos todos os cartões de crédito e vales refeição.Você pode receber nosso cardápio atualizado diariamente pelo twitter http://twitter.com/uzielrestaurant"/> \t<meta property="restaurant:image" content="http://maplink.apontador.com.br/widget?v=4.1&lat=-23.59243454&lng=-46.68677054"/> \t<meta property="restaurant:url" content="{$rootUrl}sp/s-o-paulo/restaurante/uziel-restaurante/UCV34B2P.html"/> \t<meta property="restaurant:address" content="R. Min. Jesuino Cardoso, 473"/> \t<meta property="restaurant:city" content="São Paulo"/> \t<meta property="restaurant:state" content="SP"/> \t<meta property="restaurant:country-name" content="Brasil"/> \t<meta property="restaurant:type" content="restaurant"/> META; $this->assertEquals($testMeta, $this->abm->getMeta()); $testArray = array('title' => 'Uziel Restaurante', 'description' => 'Se você procura um restaurante com variedade, qualidade com preço justo você encontra no Uziel restaurante!O preço do kilo é R$ 26,90, mas você paga no máximo R$ 15,90 por pesagem de refeições (excluindo sobremesas, bebidas e doces). Acima de 500 gramas você ainda ganha um refrescoUm bom vinho, gelatina e cafezinho são por nossa conta.Se precisar de internet você pode contar com nossa rede Wi-Fi.Nosso cardápio diário possui 5 tipos de carne todos os dias, feijoada completa e separada (feijão e carnes) às quartas, 6 tipos de massa nas quintas e 4 tipos de pizzas nassextas, além de opções de peixes todas as terças e sextas.Oferecemos convênio com descontos progressivos para empresas e um bolo com o sabor a escolha do aniversariante, caso agende com antecedência e traga mais de 10 pessoas para almoçar no seu aniversário.Aceitamos todos os cartões de crédito e vales refeição.Você pode receber nosso cardápio atualizado diariamente pelo twitter http://twitter.com/uzielrestaurant', 'image' => 'http://maplink.apontador.com.br/widget?v=4.1&lat=-23.59243454&lng=-46.68677054', 'url' => ROOT_URL . 'sp/s-o-paulo/restaurante/uziel-restaurante/UCV34B2P.html', 'address' => 'R. Min. Jesuino Cardoso, 473', 'city' => 'São Paulo', 'state' => 'SP', 'country-name' => 'Brasil', 'type' => 'restaurant'); $this->assertEquals($testArray, $this->abm->getArray()); }
/** * @param \Zend\Uri\Uri $uri */ public function parse(Uri $uri) { $this->url = $uri->toString(); $html = \OpenGraph::fetch($this->url); $query = $uri->getQueryAsArray(); // open graph $this->id = $query['v']; $this->title = $html->title; $this->description = $html->description; $this->image = urlencode($html->image); }
public static function analyze_url($url) { $graph = OpenGraph::fetch($url); $keys = array('title', 'type', 'image', 'url', 'site_name', 'description'); $returns = array(); foreach ($keys as $key) { if (!isset($graph->{$key})) { continue; } $returns[$key] = $graph->{$key}; } if ($returns && empty($returns['url'])) { $returns['url'] = $url; } return $returns; }
/** * Extract URL from a string and fetch open graph data * * @return string */ public function getUrl($string) { // Save data for AJAX response $response = []; // Extract URL from comment string preg_match(self::URL_REGEX, $string, $matches); if (!filter_var($matches[0], FILTER_VALIDATE_URL) === false) { // Fetch OpenGraph data $opengraph = OpenGraph::fetch($matches[0]); $keys = $opengraph->keys(); // Save OpenGraph data in $response if (count($keys) > 0) { foreach ($keys as $key) { $response[$key] = $opengraph->__get($key); } } } return $response; }
/** * handles the parsing of a new social-object * currently parsed: opengraph and metatags * * @param string $pUrl * @return array $pArray */ public static function fetch($pUrl, $pYiidMeta = null) { $pUrl = trim(urldecode($pUrl)); $pUrl = str_replace(" ", "+", $pUrl); try { //get the html as string $lHtml = UrlUtils::getUrlContent($pUrl, 'GET'); if (!$lHtml) { return false; } // boost performance and use alreade the header $lHeader = substr($lHtml, 0, stripos($lHtml, '</head>')); if (!$pYiidMeta) { $pYiidMeta = new YiidMeta(); } $pYiidMeta->setUrl($pUrl); if ((preg_match('~http://opengraphprotocol.org/schema/~i', $lHeader) || preg_match('~http://ogp.me/ns#~i', $lHeader) || preg_match('~property=[\\"\']og:~i', $lHeader)) && !$pYiidMeta->isComplete()) { //get the opengraph-tags $lOpenGraph = OpenGraph::parse($lHeader); $pYiidMeta->fromOpenGraph($lOpenGraph); } if (preg_match('~application/(xml|json)\\+oembed"~i', $lHeader) && !$pYiidMeta->isComplete()) { try { $lOEmbed = OEmbedParser::fetchByCode($lHeader); $pYiidMeta->fromOembed($lOEmbed); } catch (Exception $e) { // catch exception and try to go on } } if (!$pYiidMeta->isComplete()) { $lMeta = MetaTagParser::getKeys($lHtml, $pUrl); $pYiidMeta->fromMeta($lMeta); } return $pYiidMeta; } catch (Exception $e) { return false; } }
public static function fetch_image_post($post_id = '', $link = '', $comment_fbid = '') { if (!$post_id || !$link) { return; } $image = ''; if ($comment_fbid) { $app_id = FB_APP_ID; $app_secret = FB_SECRET; $url = "https://graph.facebook.com/{$comment_fbid}?access_token={$app_id}|{$app_secret}"; $obj = json_decode(file_get_contents_curl($url)); if (isset($obj->image) && $obj->image) { $image = $obj->image->url; } } var_dump($image); die; if (!empty($image)) { $graph = OpenGraph::fetch($link); var_dump($graph); die; } }
/** * Validate changes to an article before committing changes * @since Version 3.4 * @return boolean */ public function validate() { if (empty($this->title)) { throw new Exception("Validation failed: title is empty"); return false; } if (empty($this->blurb)) { throw new Exception("Validation failed: blurb is empty"); return false; } if (empty($this->body)) { throw new Exception("Validation failed: body is empty"); return false; } if (!isset($this->Author) || !$this->Author instanceof User) { $this->Author = new User($this->user_id); } /** * Try to get the featured image from OpenGraph tags */ if ($this->source && !$this->featured_image) { require_once "vendor" . DS . "scottmac" . DS . "opengraph" . DS . "OpenGraph.php"; $graph = \OpenGraph::fetch($this->source); #printArray($graph->keys()); #printArray($graph->schema); foreach ($graph as $key => $value) { if ($key == "image" && strlen($value) > 0) { $this->featured_image = $value; } } } return true; }
/** * Get html data with OpenGrap passing the Url * @param $link url * @return string data html */ public static function readContentWithOpenGraph($link) { $graph = OpenGraph::fetch($link); if (!$graph) { return false; } $url = $graph->url; $image = $graph->image; $domain = empty($url) ? parse_url($link) : parse_url($url); $domain = $domain['scheme'] . '://' . $domain['host']; // Trick to verify if the Image Url Exist because of some bad metatag dev if (self::verifyUrl($image) == false) { if (!($image[0] == '/')) { $domain = $domain . '/'; } $image = $domain . $image; } $title = $graph->title; $html = '<div class="thumbnail">'; $html .= '<a target="_blank" href="' . $link . '"><h3>' . $title . '</h3>'; $html .= empty($image) ? '' : '<img alt="" src="' . $image . '" /></a>'; $html .= empty($graph->description) ? '' : '<p class="description">' . $graph->description . '</p>'; $html .= '<a href="' . $link . '">' . $link . '</a>'; $html .= '</div>'; return $html; }
<span data-show-topic="<?php echo $post['topic_id']; ?> " data-topic-content="<?php echo $post['topic_id']; ?> " <?php echo $edit_posting != $post['topic_id'] ? '' : 'style="display: none;"'; ?> > <?php echo ForumHelpers::highlight($post['content'], $highlight); ?> <?php echo OpenGraph::extract($post['content'])->render(); ?> </span> </div> <!-- Buttons for this Posting --> <div class="buttons"> <div class="button-group"> <span data-edit-topic="<?php echo $post['topic_id']; ?> " <?php echo $edit_posting == $post['topic_id'] ? '' : 'style="display: none;"'; ?> >
/** * html with data OpenGrap * @param $link url * @return string data html */ public static function getHtmlByLink($link) { $graph = OpenGraph::fetch($link); $title = $graph->title; $html = '<div>'; $html .= '<a target="_blank" href="'.$link.'"><h3>'.$title.'</h3>'; $html .= empty($graph->image) ? '' : '<img alt="" src="'.$graph->image.'" height="160" ></a>'; $html .= empty($graph->description) ? '' : '<div>'.$graph->description.'</div>'; $html .= "</div>"; return $html; }
/** * init * */ public static function init() { add_action('wp_head', array('PressGang\\OpenGraph', 'fb_opengraph'), 5); } /** * fb_opengraph * */ public static function fb_opengraph() { $post = new \TimberPost(); $title = $post->title; $description = is_single() ? str_replace('', "'", $post->get_preview(60, true, false, true)) : get_bloginfo('description', 'display'); $img = has_post_thumbnail($post->id) ? wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large')[0] : (get_theme_mod('og_img') ? get_theme_mod('og_img') : esc_url(get_theme_mod('logo'))); $type = is_author() ? 'profile' : (is_single() ? 'article' : 'website'); $url = get_permalink(); $url = rtrim(esc_url(apply_filters('og_url', $url))); if (!substr($url, -1) === '/') { $url .= '/'; // slash fixes Facebook Debugger "Circular Redirect Path" } $open_graph = array('site_name' => esc_attr(apply_filters('og_site_name', get_bloginfo())), 'title' => esc_attr(apply_filters('og_title', $title)), 'description' => esc_attr(apply_filters('og_description', $description)), 'type' => esc_attr(apply_filters('og_type', $type)), 'url' => $url, 'image' => esc_url(apply_filters('og_image', $img))); \Timber::render('open-graph.twig', array('open_graph' => $open_graph)); } } OpenGraph::init();
/** * Displays the page for generating HTML code for pocket entry */ public function code_generation_page() { ?> <div class="wrap"> <h2 class="pkt-nws-gnrtr"><?php _e('Retrieve Items in Pocket and Generate HTML Code', self::DOMAIN); ?> </h2> <p><?php _e('Specify search condition for Pocket data retrieval and push the button below.', self::DOMAIN); ?> </p> <div class="pkt-nws-gnrtr"> <form action="" method="post"> <div> <label><?php _e('State', self::DOMAIN); ?> </label><br /> <select name="<?php echo PocketUtil::OPT_STATE; ?> " class="dropdown"> <option value="all" selected><?php _e('all (both unread and archived items)', self::DOMAIN); ?> </option> <option value="unread"><?php _e('only unread items', self::DOMAIN); ?> </option> <option value="archive"><?php _e('only archived items', self::DOMAIN); ?> </option> </select> </div> <div> <label><?php _e('Favorite', self::DOMAIN); ?> </label><br /> <select name="<?php echo PocketUtil::OPT_FAVORITE; ?> " class="dropdown"> <option value ="" selected><?php _e('all (both un-favorited and favorited items)', self::DOMAIN); ?> </option> <option value="0"><?php _e('only un-favorited items', self::DOMAIN); ?> </option> <option value="1"><?php _e('only favorited items', self::DOMAIN); ?> </option> </select> </div> <div> <label><?php _e('Tag', self::DOMAIN); ?> </label><br /> <input type="text" class="text" name="<?php echo PocketUtil::OPT_TAG; ?> " size="60" value="" /> </div> <div> <label><?php _e('Content Type', self::DOMAIN); ?> </label><br /> <select name="<?php echo PocketUtil::OPT_CONTENT_TYPE; ?> " class="dropdown"> <option value ="" selected><?php _e('all', self::DOMAIN); ?> </option> <option value="article"><?php _e('only articles', self::DOMAIN); ?> </option> <option value="video"><?php _e('only videos or articles with embedded videos', self::DOMAIN); ?> </option> <option value="image"><?php _e('only images', self::DOMAIN); ?> </option> </select> </div> <div> <label><?php _e('Sort', self::DOMAIN); ?> </label><br /> <select name="<?php echo PocketUtil::OPT_SORT; ?> " class="dropdown"> <option value ="newest" selected><?php _e('items in order of newest to oldest', self::DOMAIN); ?> </option> <option value="oldest"><?php _e('items in order of oldest to newest', self::DOMAIN); ?> </option> <option value="title"><?php _e('items in order of title alphabetically', self::DOMAIN); ?> </option> <option value="site"><?php _e('items in order of URL alphabetically', self::DOMAIN); ?> </option> </select> </div> <div> <label><?php _e('Search', self::DOMAIN); ?> </label><br /> <input type="text" class="text" name="<?php echo PocketUtil::OPT_SEARCH; ?> " size="60" value="" /> </div> <div> <label><?php _e('Domain', self::DOMAIN); ?> </label><br /> <input type="text" class="text" name="<?php echo PocketUtil::OPT_DOMAIN; ?> " size="60" value="" /> </div> <div> <label><?php _e('Since (YYYY-MM-DD HH24:MM)', self::DOMAIN); ?> </label><br /> <input type="text" class="text" name="<?php echo PocketUtil::OPT_SINCE; ?> " size="60" value="" /> </div> <div> <label><?php _e('Count', self::DOMAIN); ?> </label><br /> <input type="text" class="text" name="<?php echo PocketUtil::OPT_COUNT; ?> " size="60" value="" /> </div> <div> <label><?php _e('Offset', self::DOMAIN); ?> </label><br /> <input type="text" class="text" name="<?php echo PocketUtil::OPT_OFFSET; ?> " size="60" value="" /> </div> <input type="hidden" name="action" value="generate" /> <div> <input type="submit" class="button button-primary" value="<?php _e('Generate', self::DOMAIN); ?> " /> </div> </form> </div> </div> <br /> <?php if ($_POST["action"] === 'generate') { $consumer_key = get_option(self::DB_CONSUMER_KEY); $access_token = get_option(self::DB_ACCESS_TOKEN); $format = get_option(self::DB_FORMAT); $state = $_POST[PocketUtil::OPT_STATE]; $favorite = $_POST[PocketUtil::OPT_FAVORITE]; $tag = $_POST[PocketUtil::OPT_TAG]; $contentType = $_POST[PocketUtil::OPT_CONTENT_TYPE]; $sort = $_POST[PocketUtil::OPT_SORT]; $search = $_POST[PocketUtil::OPT_SEARCH]; $domain = $_POST[PocketUtil::OPT_DOMAIN]; $since = $_POST[PocketUtil::OPT_SINCE]; $count = $_POST[PocketUtil::OPT_COUNT]; $offset = $_POST[PocketUtil::OPT_OFFSET]; if (isset($state) && $state) { $option_params[PocketUtil::OPT_STATE] = $state; } if ($favorite == 0 || $favorite == 1) { $option_params[PocketUtil::OPT_FAVORITE] = $favorite; } if (isset($tag) && $tag) { $option_params[PocketUtil::OPT_TAG] = $tag; } if (isset($contentType) && $contentType) { $option_params[PocketUtil::OPT_CONTENT_TYPE] = $contentType; } if (isset($sort) && $sort) { $option_params[PocketUtil::OPT_SORT] = $sort; } if (isset($search) && $search) { $option_params[PocketUtil::OPT_SEARCH] = $search; } if (isset($domain) && $domain) { $option_params[PocketUtil::OPT_DOMAIN] = $domain; } if (isset($since) && $since) { $gmt_time = get_gmt_from_date($since); $option_params[PocketUtil::OPT_SINCE] = strtotime($gmt_time); } if (isset($count) && $count) { $option_params[PocketUtil::OPT_COUNT] = $count; } if (isset($offset) && $offset) { $option_params[PocketUtil::OPT_OFFSET] = $offset; } $option_params[PocketUtil::OPT_DETAIL_TYPE] = 'complete'; //$debug_mode = true; if (isset($debug_mode) && $debug_mode) { echo 'consumer_key: ' . $consumer_key . '<br />'; echo 'access_token: ' . $access_token . '<br />'; echo 'state: ' . $state . '<br />'; echo 'favorite: ' . $favorite . '<br />'; echo 'tag: ' . $tag . '<br />'; echo 'contentType: ' . $contentType . '<br />'; echo 'sort: ' . $sort . '<br />'; echo 'search: ' . $search . '<br />'; echo 'domain: ' . $domain . '<br />'; echo 'since: JST-> ' . $since . ' GMT-> ' . $gmt_time . '<br />'; echo 'count: ' . $count . '<br />'; echo 'offset: ' . $offset . '<br />'; echo 'Default timezone: ' . date_default_timezone_get() . '<br />'; echo 'Local timezone: ' . get_option('timezone_string') . '<br />'; echo 'Difference in time from default timezone: ' . get_option('gmt_offset') . '<br />'; echo 'Array of option parameters:<br />'; print_r($option_params); } $pocket_util = new PocketUtil(); $pocket_body = $pocket_util->retrieveItem($consumer_key, $access_token, $option_params); $feedly_util = new FeedlyUtil(); if (!empty($pocket_body)) { //Check if there is mached data. if (!empty($pocket_body->list)) { echo '<div class="wrap">'; echo '<h2 class="pkt-nws-gnrtr">' . __('Generated HTML Code', self::DOMAIN) . '</h2>'; echo '<p>' . __('Generated HTML code is as follows. Copy and paste it into your post.', self::DOMAIN) . '</p>'; echo '<div class="pkt-nws-gnrtr">'; echo '<label>' . __('HTML Code', self::DOMAIN) . '</label><br />'; echo '<textarea class="text" style="width:500px;height:300px;">'; foreach ($pocket_body->list as $pocket_item) { //Post URL $html_code = str_replace(self::FRMT_POST_URL, $pocket_item->{PocketUtil::REF_RESOLVED_URL}, stripslashes($format)); //Post title $html_code = str_replace(self::FRMT_POST_TITLE, $pocket_item->{PocketUtil::REF_RESOLVED_TITLE}, $html_code); //Site name and site URL if (strpos($format, self::FRMT_SITE_NAME) !== false || strpos($format, self::FRMT_SITE_URL) !== false) { $url_util = new URLUtil($pocket_item->{PocketUtil::REF_RESOLVED_URL}); $feedly_info_flag = false; do { $feedly_body = $feedly_util->getSiteInfo($url_util->getURL()); $site_name = $feedly_body->results[0]->{FeedlyUtil::REF_SITE_NAME}; $site_url = $feedly_body->results[0]->{FeedlyUtil::REF_SITE_URL}; if (isset($site_name) && isset($site_url)) { $html_code = str_replace(self::FRMT_SITE_NAME, $site_name, $html_code); $html_code = str_replace(self::FRMT_SITE_URL, $site_url, $html_code); $feedly_info_flag = true; break; } //Check next path existence } while ($url_util->next()); if (!$feedly_info_flag) { //Site URL (URL of top page) retrieval $site_url = $pocket_util->getBaseUrl($pocket_item->{PocketUtil::REF_RESOLVED_URL}); $html_code = str_replace(self::FRMT_SITE_URL, $site_url, $html_code); //Information retrieval of OGP $graph = OpenGraph::fetch($pocket_item->{PocketUtil::REF_RESOLVED_URL}); if (isset($graph->site_name)) { // Content of og:site_name $html_code = str_replace(self::FRMT_SITE_NAME, $graph->site_name, $html_code); } else { // Content of title in top page $site_name = $pocket_util->getSiteName($pocket_item->{PocketUtil::REF_RESOLVED_URL}); $html_code = str_replace(self::FRMT_SITE_NAME, $site_name, $html_code); } } } //Post excerpt if (strpos($format, self::FRMT_POST_EXCERPT) !== false) { if (isset($pocket_item->{PocketUtil::REF_EXCERPT})) { // Content of excerpt in Pocket data $html_code = str_replace(self::FRMT_POST_EXCERPT, $pocket_item->{PocketUtil::REF_EXCERPT}, $html_code); } else { //Information retrieval of OGP $graph = OpenGraph::fetch($pocket_item->{PocketUtil::REF_RESOLVED_URL}); // Content of og:description $html_code = str_replace(self::FRMT_POST_EXCERPT, $graph->description, $html_code); } } //Post image if (strpos($format, self::FRMT_POST_IMAGE) !== false) { if (isset($graph->image)) { //Information retrieval of OGP $graph = OpenGraph::fetch($pocket_item->{PocketUtil::REF_RESOLVED_URL}); $html_code = str_replace(self::FRMT_POST_IMAGE, $graph->image, $html_code); } } echo htmlspecialchars($html_code); } echo '</textarea>'; echo '</div>'; echo '</div>'; } else { echo '<div class="pkt-nws-gnrtr">'; echo '<span class="red">' . __('INFO: Pocket data matching your specified condition was not found.', self::DOMAIN) . '</span>'; echo '</div>'; } } else { echo '<div class="pkt-nws-gnrtr">'; echo '<span class="red">' . __('ERROR: Pocket data retrieval failed.', self::DOMAIN) . '</span>'; echo '</div>'; } } }
<?php require_once 'OpenGraph.php'; $url = 'http://www.yelp.com/biz/the-restaurant-at-wente-vineyards-livermore-2'; $graph = new OpenGraph($url); print_r($graph->get_one('title')); print_r($graph->get_all());
/** * Get OpenGraph tags from a specified URL * Really stupid and elaborate Memcached expiry handling is due to a bug in Debian's PHP5-Memcached package * * @since Version 3.10.0 * @param string $url * @return array */ public static function GetOpenGraphTags($url) { $Memcached = AppCore::GetMemcached(); $mckey = md5($url); if ($result = $Memcached->fetch($mckey)) { $exp = $Memcached->fetch(sprintf("%s-exp", $mckey)); if ($exp < time()) { $Memcached->delete($mckey); $Memcached->delete(sprintf("%s-exp", $mckey)); $result = false; } } if (!$result) { /** * Ensure our OG handler is loaded */ require_once "vendor" . DS . "scottmac" . DS . "opengraph" . DS . "OpenGraph.php"; $graph = \OpenGraph::fetch($url); $result = array(); foreach ($graph as $key => $value) { $result[$key] = $value; } $Memcached->save($mckey, $result, 0); // 0 or will not cache $Memcached->save(sprintf("%s-exp", $mckey), strtotime("+1 day"), 0); // alternate method of specifying expiry } return $result; }
public function __construct($url) { if ($url) { self::$og_content = self::get_graph($url); } }
$manageUsers = new Permission; $manageUsers->name = 'manage_users'; $manageUsers->display_name = 'Manage Users'; $manageUsers->save(); $owner->perms()->sync(array($managePosts->id,$manageUsers->id)); $admin->perms()->sync(array($managePosts->id)); */ //$bool = $user->hasRole("Owner"); // false //$bool = $user->hasRole("Admin"); // true //$bool = $user->can("manage_posts"); // true //$bool = $user->can("manage_users"); // false SEOMeta::setTitle('setTitle'); SEOMeta::setDescription('setDescription'); // is automatically limited to 160 characters OpenGraph::addImage('addImage.png'); return View::make('hello'); }); // Sitemap Route::get('sitemap', function () { $posts = DB::table('iumslas')->orderBy('created_at', 'desc')->get(); foreach ($posts as $post) { $element = array('location' => "/sitemap-posts.xml", 'last_modified' => $post->created_at, 'change_frequency' => 'weekly', 'priority' => '0.90'); SEOSitemap::addRaw($element); } return Response::make(SEOSitemap::generate(), 200, array('Content-Type' => 'text/xml')); }); //RSS Route::get('/rss', function () { $feed = Rss::feed('2.0', 'UTF-8'); $feed->channel(array('title' => 'Channel\'s title', 'description' => 'Channel\'s description', 'link' => 'http://www.test.com/'));
public function testFetchReturnsFalseForWebsiteWithNoOpenGraphMetadata() { $this->assertEquals(FALSE, OpenGraph::fetch('http://www.example.org/')); }
public function getOGLocales() { // Use current locale $locale = i18n::get_locale(); // Check locale is valid if (OpenGraph::is_locale_valid($locale)) { return $locale; } // Return default return OpenGraph::get_default_locale(); }
public function getOpenGraphURLs() { return OpenGraph::extract($this->description); }
/* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { return view('home'); }); Route::post('fetch', function () { require_once 'app/Classes/OpenGraph.php'; $graph = OpenGraph::fetch(Input::get('url')); foreach ($graph as $key => $value) { $output[$key] = $value; } return $output; }); Route::post('sendtweet', function () { $file = file_get_contents(Input::get('image')); $file = base64_encode($file); $uploaded_media = Twitter::uploadMedia(['media_data' => $file]); return Twitter::postTweet(['status' => Input::get('text'), 'media_ids' => $uploaded_media->media_id_string]); }); Route::get('twitter/login', ['as' => 'twitter.login', function () { // your SIGN IN WITH TWITTER button should point to this route $sign_in_twitter = true; $force_login = false;
/** * @expectedException \Exception */ public function testEmptyrequiredFields() { $og = new OpenGraph(); $og->render(); }
<?php /** * Link Post Format template */ require_once get_template_directory() . '/inc/OpenGraph.php'; $graph = OpenGraph::fetch(get_field('external_url')); if (!empty($graph)) { $og_title = $graph->__isset('title') ? $graph->__get('title') : ''; $og_desc = $graph->__isset('description') ? $graph->__get('description') : ''; $og_image = $graph->__isset('image') ? $graph->__get('image') : ''; } $page_id = get_option('page_for_posts'); ?> <h1 class="no-pad"><?php the_title(); ?> </h1> <hr style="border-color: <?php __the_field('color_theme', 'esc_attr', $page_id); ?> ;" /> <?php the_content(); ?> <hr style="border-color: <?php __the_field('color_theme', 'esc_attr', $page_id); ?> ;" /> <div class="row open-graph-data">
Route::get('users/create', 'UsersController@create'); Route::post('users', 'UsersController@store'); Route::get('users/login', 'UsersController@login'); Route::post('users/login', 'UsersController@doLogin'); Route::get('users/confirm/{code}', 'UsersController@confirm'); Route::get('users/forgot_password', 'UsersController@forgotPassword'); Route::post('users/forgot_password', 'UsersController@doForgotPassword'); Route::get('users/reset_password/{token}', 'UsersController@resetPassword'); Route::post('users/reset_password', 'UsersController@doResetPassword'); Route::get('users/logout', 'UsersController@logout'); Route::get('users/loginWithFacebook', 'UsersController@loginWithFacebook'); Route::get('/', function () { //for seo SEOMeta::setTitle('Dashboard'); OpenGraph::addImage('addImage.png'); OpenGraph::type('article'); Twitter::type('summary'); Twitter::addImage('twitter.png'); //to change language App::setlocale('tr'); return View::make('hello'); }); // Sitemap | Because of I have only users table, I use users table. Route::get('sitemap', function () { //for sitemap $users = DB::table('users')->orderBy('created_at', 'desc')->get(); foreach ($users as $user) { $element = array('location' => "/" . $user->slug, 'last_modified' => $user->created_at, 'change_frequency' => 'weekly', 'priority' => '0.90'); SEOSitemap::addRaw($element); } return Response::make(SEOSitemap::generate(), 200, array('Content-Type' => 'text/xml'));