danharper / inbox-actions
Inbox actions,适用于Gmail和其他任何兼容的电子邮件客户端
v1.0.0
2015-12-07 13:22 UTC
Requires (Dev)
- phpunit/phpunit: 4.3.x
This package is auto-updated.
Last update: 2024-09-05 08:49:57 UTC
README
一个小型库,用于生成Schema.org标记以嵌入电子邮件,以实现“邮箱中的操作”。
composer require danharper/inbox-actions
用法
迄今为止,以下来自Gmail的“操作”被支持
查看
<?php use DanHarper\InboxActions\InboxAction; $action = InboxAction::ViewAction('View Report', 'http://example'); echo $action;
输出
<script type="application/ld+json"> { "@context": "http://schema.org", "@type": "EmailMessage", "action": { "@type": "ViewAction", "name": "View Report", "url": "http://example" } } </script>
您还可以添加您组织的详细信息
<?php InboxAction::ViewAction('ViewReport', 'http://example') ->publisher('Acme', 'http://acme');
<script type="application/ld+json"> { "@context": "http://schema.org", "@type": "EmailMessage", "action": { "@type": "ViewAction", "name": "View Report", "url": "http://example" }, "publisher": { "@type": "Organization", "name": "Acme", "url": "http://acme" } } </script>
RSVP
<?php use DanHarper\InboxActions\InboxAction; use DanHarper\InboxActions\Schemas\PostalAddress; InboxAction::RSVP('Taco Night') ->at(new DateTime('2015-04-18 15:30'), new DateTime('2015-04-18 16:30')) ->address(new PostalAddress( 'Google', '24 Willie Mays Plaza', 'San Francisco', 'CA', '94107', 'USA' )) ->yes('http://acme') ->no('http://acme') ->maybe('http://acme');
当echo
'd时,结果如下
<script type="application/ld+json"> { "@context": "http://schema.org", "@type": "Event", "name": "Taco Night", "startDate": "2015-04-18T15:30:00+0000", "endDate": "2015-04-18T16:30:00+0000", "location": { "@type": "Place", "address": { "@type": "PostalAddress", "name": "Google", "streetAddress": "24 Willie Mays Plaza", "addressLocality": "San Francisco", "addressRegion": "CA", "postalCode": "94107", "addressCountry": "USA" } }, "action": [ { "@type": "RsvpAction", "attendance": "http://schema.org/RsvpAttendance/Yes", "handler": { "@type": "HttpActionHandler", "method": "http://schema.org/HttpRequestMethod/GET", "url": "http://acme" } }, { "@type": "RsvpAction", "attendance": "http://schema.org/RsvpAttendance/No", "handler": { "@type": "HttpActionHandler", "method": "http://schema.org/HttpRequestMethod/GET", "url": "http://acme" } }, { "@type": "RsvpAction", "attendance": "http://schema.org/RsvpAttendance/Maybe", "handler": { "@type": "HttpActionHandler", "method": "http://schema.org/HttpRequestMethod/GET", "url": "http://acme" } } ] } </script>
有多种方式可以定义事件日期、地址和可能的响应
<?php InboxAction::RSVP('Taco Night') // you can define a date range with "at" ->at(new DateTime('2015-04-18 15:30'), new DateTime('2015-04-18 16:30')) // OR you can define the dates separately ->start(new DateTime('2015-04-18 15:30')) ->finish(new DateTime('2015-04-18 16:30')) // you MUST define at least a start date // you can specify the address by providing an Address object: ->address(new PostalAddress( 'Google', '24 Willie Mays Plaza', 'San Francisco', 'CA', '94107', 'USA' )) // OR with a callback where the address is given to you: ->address(function(PostalAddress $adr) { // you can skip any of these fields $adr->name('Google') ->street('24 Willie Mays Plaza') ->city('San Francisco') ->region('CA') ->postCode('94107') ->country('USA'); }) // you MUST specify both "yes" and "no" response URLs ->yes('http://acme?response=yes') ->no('http://acme?response=no') // you MAY specify a "maybe" response URL ->maybe('http://acme?response=maybe') // by default, responses will be GET requests // you can be explicit, or use a POST request instead: ->yes('http://acme', 'GET') ->yes('http://acme', 'POST');
确认 / 保存
确认操作和保存操作几乎相同。您可以在下面的ConfirmAction
与SaveAction
之间进行交换以改变语义。
<?php use DanHarper\InboxActions\InboxAction; InboxAction::ConfirmAction('Approve Expense', 'http://acme.com'); // Also supports publisher details InboxAction::ConfirmAction('Approve Expense', 'http://acme.com') ->publisher('Acme', 'http://acme'); // Use POST for URL handler InboxAction::ConfirmAction('Approve Expense')->handler('http://acme.com', 'POST'); // Require additional confirmation from user after clicking button InboxAction::ConfirmAction('Approve Expense', 'http://acme') ->requireConfirmation();
示例输出
<script type="application/ld+json"> { "@context": "http://schema.org", "@type": "EmailMessage", "action": { "@type": "ConfirmAction", "name": "Approve Expense", "handler": { "@type": "HttpActionHandler", "method": "http://schema.org/HttpRequestMethod/GET", "url": "http://acme.com/?approve=29394&auth=28usj92k", "requiresConfirmation": true } }, "publisher": { "@type": "Organization", "name": "Acme Incorporated", "url": "http://acme.org" } } </script>