newscoop / facebook-newscoop-bundle
集成Newscoop和Facebook的实用服务
Requires
- php: >=5.3.3
- ext-curl: *
- kriswallsmith/buzz: >=v0.9
- newscoop/plugins-installer: >=v0.2
This package is auto-updated.
Last update: 2024-09-24 04:09:53 UTC
README
特性
- Facebook缓存共享URL以提高性能。当我们想更改Newscoop文章的标题或描述时,这可能会引起问题,因为Facebook仍然保留着旧版本。此插件通过清除Facebook上的文章缓存并更新Open Graph标签来解决这个问题。
- 此插件还提供了一种简单的方法,通过简单的模板块生成所有必需的Open Graph标签。
- Newscoop提供了一种提前安排文章发布的方法,但在发布文章之前,您不能在Facebook上计划公告,因为Facebook不会获取文章元数据。此插件公开了一个特殊的Facebook爬虫URL,以便您可以使用安排的文章计划帖子。当这些安排的文章发布时,此URL将重定向读者到真实的文章。
安装
步骤 1
在Newscoop服务器控制台中,运行以下命令
$ php application/console plugins:install "newscoop/facebook-newscoop-bundle" --env=prod
此插件将被安装到newscoop/plugins/Newscoop
目录。
步骤 2
转到Newscoop中的文章编辑页面,在右侧边栏中查看Facebook插件。
有关生命周期订阅者管理的更多信息。
插件的数据表
此插件只有一个实体:Facebook.php
。插件安装后,您的Newscoop数据库将有一个新的表:plugin_facebook_informations
。
此表保存有关文章的Facebook信息,例如
article
- 文章IDlanguage
- 文章的语言IDtitle
- 文章标题description
- 文章描述created_at
- 信息添加的日期is_active
- 信息状态
使用Smarty插件生成Open Graph标签
在Newscoop/FacebookNewscoopBundle/Resources/smartyPlugins
目录中,您可以找到文件:block.facebook_meta_block.php
。
此文件是一个Facebook元数据块插件。它为页面生成Facebook元信息。Smarty插件将自动自动加载,并在您的模板中可用。
要将Smarty插件生成的元数据测试和显示,请将此块放入_html-head.tpl
。
{{ facebook_meta_block admins="123422,234223432,234234234,23423423" }}{{ /facebook_meta_block }}
Smarty插件将生成HTML代码,例如
//ex.
<meta property="og:title" content="Lionel Messi: the Argentinean who makes children dream all over the world" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http:/newscoop.dev/en/may2013/sports/80/Lionel-Messi-the-Argentinean-who-makes-children-dream-all-over-the-world.htm" />
<meta property="og:site_name" content="The New Custodian" />
<meta property="og:locale" content="en" />
<meta property="og:description" content="Malorum prompta maiestatis ius at, vim movet cotidieque ei. Erroribus torquatos vel et, pri nostro causae gubergren id. Per ut cetero laoreet recteque, cetero lucilius phaedrum his at" />
<meta property="article:section" content="Sports" />
<meta property="article:author" content="Amerigo Vespucci" />
<meta property="article:published_time" content="2013-05-02 08:17:08" />
<meta property="fb:app_id" content="499467366771848" />
<meta property="fb:admins" content="123422,234223432,234234234,23423423" />
<meta property="og:image" content="http://newscoop.dev/images/cms-image-000000124.jpg" />
您可以在Facebook开发者文档中了解更多关于Open Graph标签的信息。
在Facebook上提交和计划发布的文章
此插件为尚未发布的文章提供特殊处理。
URI具有以下格式:/f/+{webcode}
例如:/f/+j6gd4
,可以在文章编辑器的插件侧边栏小部件中找到。
默认情况下,仅对Facebook爬虫渲染简单的HTML结构和Open Graph元标签。您可以使用包含在您的模板中的__fb_submited_article.tpl
模板文件来覆盖此内容。
模板输出示例
<!DOCTYPE html>
<html xmlns:og="http://ogp.me/ns#" xmlns:fb="https://#/2008/fbml">
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article#">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>test article</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<meta name="description" content="">
<meta name="keywords" content="" />
<meta property="og:title" content="test article" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://newscoop.dev/en/2/2/130/" />
<meta property="og:site_name" content="test publication" />
<meta property="og:description" content="" />
<meta property="article:section" content="police" />
<meta property="og:image" content="http://newscoop.dev/images/cms-image-000000011.jpg" />
<meta property="article:publisher" content="https://#/newscoop.dev" />
<meta property="og:author" content="http://facebook.com/newscoop.dev" />
<meta name="author" content="test publication" />
</head>
</html>
插件应用实例
当您进入Newscoop的文章编辑屏幕时,插件将检查数据库中是否已存在该文章的信息。如果没有,它将连接到Facebook Graph API并下载所有必要的信息。然后,将此信息插入到Newscoop数据库中。
如果连接到Facebook成功,则会在屏幕 1上显示状态消息。
屏幕 1:通用插件视图。
要清除文章缓存,只需单击在Facebook上清除文章缓存
按钮,就会显示一条消息(参见屏幕2)。
屏幕2:按钮点击后的连接消息。
如果由于某些原因无法连接到Facebook,我们将看到一条错误消息(参见屏幕3)。
屏幕3:连接到Facebook失败 - 状态消息。
许可证
本插件依据GNU通用公共许可证v3发布。您可以在源代码中阅读完整的许可证。
关于
Newscoop的Facebook插件是Sourcefabric z.ú.的倡议。