A PHP 5.3+ and PHP 7.3 framework for OpenGraph Protocol

Overview

Opengraph

Build Status

Test with Atoum

cd Opengraph/
curl -s https://getcomposer.org/installer | php
php composer.phar install --dev
./vendor/atoum/atoum/bin/atoum --glob Tests/Units/

Writer

<?php
namespace Application;

require_once __DIR__ . '/../src/Opengraph/Meta.php';
require_once __DIR__ . '/../src/Opengraph/Opengraph.php';
require_once __DIR__ . '/../src/Opengraph/Writer.php';

use Opengraph;

$writer = new Opengraph\Writer();
$writer->append(Opengraph\Writer::OG_TITLE, 'The Rock');
$writer->append(Opengraph\Writer::OG_TYPE, Opengraph\Writer::TYPE_VIDEO_MOVIE);
$writer->append(Opengraph\Writer::OG_URL, 'http://www.imdb.com/title/tt0117500/');
$writer->append(Opengraph\Writer::OG_IMAGE, 'http://ia.media-imdb.com/images/rock.jpg');

echo $writer->render() . PHP_EOL;

?>

Output

    <meta property="og:title" content="The Rock" />
    <meta property="og:type" content="video.movie" />
    <meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
    <meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />

Reader

<?php
namespace Application;

require_once __DIR__ . '/../src/Opengraph/Meta.php';
require_once __DIR__ . '/../src/Opengraph/Opengraph.php';
require_once __DIR__ . '/../src/Opengraph/Reader.php';

use Opengraph;

$reader = new Opengraph\Reader();
$reader->parse(file_get_contents('http://www.imdb.com/title/tt0117500/'));
print_r($reader->getArrayCopy());

?>

Output

Array
(
    [og:url] => http://www.imdb.com/title/tt0117500/
    [og:title] => Rock (1996)
    [og:type] => video.movie
    [og:image] => Array
        (
            [0] => Array
                (
                    [og:image:url] => http://ia.media-imdb.com/images/M/MV5BMTM3MTczOTM1OF5BMl5BanBnXkFtZTYwMjc1NDA5._V1._SX98_SY140_.jpg
                )

        )

    [og:site_name] => IMDb
    [fb:app_id] => 115109575169727
)
You might also like...
TiDB is an open source distributed HTAP database compatible with the MySQL protocol
TiDB is an open source distributed HTAP database compatible with the MySQL protocol

What is TiDB? TiDB ("Ti" stands for Titanium) is an open-source NewSQL database that supports Hybrid Transactional and Analytical Processing (HTAP) wo

This tool can write the monolog standard log directly to clickhouse in real time via the tcp protocol

log2ck This tool can write the monolog standard log directly to clickhouse in real time via the tcp protocol. If you can write regular rules, other st

Google Analytics Measurement Protocol Package for Symfony

Google Analytics Measurement Protocol Package for Symfony. Supports all GA Measurement Protocol API methods.

The XP Framework is an all-purpose, object oriented PHP framework.

XP Framework Core This is the XP Framework's development checkout. Installation If you just want to use the XP Framework, grab a release using compose

A panel created based on the Zend Framework MVC framework
A panel created based on the Zend Framework MVC framework

🚀 Painel MyZap2.0 Com ZendFramework 3 Descrição Esse é um painel criado como estudo pessoal do framework (Zend Framework MVC) não foi criado para fin

Developer-friendly framework heavily inspired by Laravel and based on Timber and Wpemerge solutions for WordPress themes development with Bedrock folder structure

Lightweight Brocooly (Brocket) Improved Controllers, Middleware and Routers, but slightly less powerful Container Open beta. Package in development Cr

Simple custom chat bot developing framework for telegram, qq and more in PHP (the best language)
Simple custom chat bot developing framework for telegram, qq and more in PHP (the best language)

RinoBot RinoBot 是一个为统一聊天机器人扩展开发的框架,编写一份插件用于多种机器人协议。 简体中文 | English 🚧 开发中 🚧 暂不适用于生产环境 特性 插件扩展机制 一份代码运行于多平台多协议机器人 并减小开发难度 插件提供 Yaml 配置 供使用者修改 基于机器人 We

A hacky PHP script to download posts, images, videos and framework grading from Parent Zone

ParentZoneDownloader A hacky PHP script to download posts, images, videos and framework grading from Parent Zone Pre-Requisites Tested on PHP 7.4, but

This example shows how to use Anychart library with the PHP programming language, Laravel framework and MySQL database.
This example shows how to use Anychart library with the PHP programming language, Laravel framework and MySQL database.

PHP basic template This example shows how to use Anychart library with the PHP programming language, Laravel framework and MySQL database. Running To

Comments
  • Fallback Title and Description values

    Fallback Title and Description values

    I've found, in my usage, that it's useful to have access to the title tag and meta description as fallbacks when reading the meta data.

    This PR adds this data to the associative array returned by Reader->parse() with keys "non-og-title" and "non-og-description"

    Note: This does disturb the conceptual function of Meta (ie. reading and re-writing the read results), which is why I made it optional. This might also want some refactoring.

    Enhancement 
    opened by samward1985 4
  • Update Opengraph.php

    Update Opengraph.php

    When running multiple url's after each other, the storage isn't reset;

    $data = array();
    $reader = new Opengraph\Reader();
    $reader->parse(file_get_contents('http://www.imdb.com/title/tt0117500/'));
    $data[] = $reader->getArrayCopy();
    $reader = new Opengraph\Reader();
    $reader->parse(file_get_contents('http://nu.nl/'));
    $data[] = $reader->getArrayCopy();
    

    When the second URL doesn't have Opengraph data, it shows the data of the first URL.

    opened by nielsz 1
  • Redesign of Parser and Render

    Redesign of Parser and Render

    Parser replaced the class Reader and Render replaced the class Writer. It is now possible to render Opengraph in Json and restore it with ParserJson. The new design allows new Parser types and new Render types to be created without the need to change the Opengraph class (Open-closed principle of SOLID).

    opened by brunomp 4
  • Feat.: Write Opengraph from Json

    Feat.: Write Opengraph from Json

    Hello,

    I created a function that makes an Opengraph from a Json. I did not do the Unity Test because I do not know how to use Atoum.

    I needed this function because I saved in the database the Json returned from getArrayCopy() and I need to restore the object afterwards.

    What do you think? Thank you.

    opened by brunomp 3
Releases(v2.0.0)
Owner
Axel Etcheverry
Architect at Angell.bike, Previous: Architect @SomfyProtect, Senior Developer @MolotovTv, Apple/Mac  Addict, Photographer http://500px.com/euskadi31
Axel Etcheverry
MajorDoMo is an open-source DIY smarthome automation platform aimed to be used in multi-protocol and multi-services environment.

MajorDoMo (Major Domestic Module) is an open-source DIY smarthome automation platform aimed to be used in multi-protocol and multi-services environment. It is based on web-technologies stack and ready to be delivered to any modern device. It is very flexible in configuration with OOP paradigm used to set up automation rules and scripts. This platform can be installed on almost any personal computer running Windows or Linux OS.

Sergei Jeihala 369 Dec 30, 2022
> Create e-wallet, send money, withdraw and check balance all via USSD protocol

Mobile Money USSD solution Create e-wallet, send money, withdraw and check balance all via USSD protocol Create e-wallet Step 1 Step 2 Step 3 Step 4 S

Emmanuel HAKORIMANA 1 Nov 3, 2021
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers

Magento 2 SMTP Extension - Gmail, G Suite, Amazon SES, Office 365, Mailgun, SendGrid, Mandrill and other SMTP servers. For Magento 2.0.x, 2.1.x, 2.2.x

MagePal :: Magento Extensions 303 Oct 7, 2022
Starless Sky is a network protocol for secure identities, providing the use of assymetric identities, public information, end-to-end messaging and smart contracts

Descentralized network protocol providing smart identity over an secure layer. What is the Starless Sky Protocol? Starless Sky is a network protocol f

Starless Sky Protocol 3 Jun 19, 2022
PHP Protobuf - Google's Protocol Buffers for PHP

This repository is no longer maintained Since Google's official Protocol Buffers supports PHP language, it's unjustifiable to maintain this project. P

Allegro Tech 912 Dec 16, 2022
A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

Felix Becker 1.1k Jan 4, 2023
A PHP implementation of the Unleash protocol aka Feature Flags in GitLab.

A PHP implementation of the Unleash protocol aka Feature Flags in GitLab. This implementation conforms to the official Unleash standards and implement

Dominik Chrástecký 2 Aug 18, 2021
An implementation of the Minecraft: Bedrock Edition protocol in PHP

BedrockProtocol An implementation of the Minecraft: Bedrock Edition protocol in PHP This library implements all of the packets in the Minecraft: Bedro

PMMP 94 Jan 6, 2023
Spotweb is a decentralized usenet community based on the Spotnet protocol.

Spotweb is a decentralized usenet community based on the Spotnet protocol. Spotweb requires an operational webserver with PHP5.6 installed, it

Spotweb 433 Jan 1, 2023
Spotweb is a decentralized usenet community based on the Spotnet protocol.

Spotweb Spotweb is a decentralized usenet community based on the Spotnet protocol. Spotweb requires an operational webserver with PHP5.6 installed, it

[sCRiPTz-TEAM] 2 Nov 29, 2021