itscoding / facebook-connector
该软件包已被弃用,不再维护。未建议替代包。
将网站连接到Facebook页面
1.4.0
2019-04-16 21:30 UTC
Requires
- ext-json: *
- craftcms/cms: ^3.0.0
- facebook/graph-sdk: ^5.6
Requires (Dev)
- codacy/coverage: dev-master
- phpunit/phpunit: ^6.5
- squizlabs/php_codesniffer: ^3.1
This package is auto-updated.
Last update: 2021-06-27 22:09:59 UTC
README
通过简单设置连接您的网站与Facebook页面
FacebookConnector 简介
使用简单设置将Craft条目作为Facebook帖子发布
要求
此插件需要Craft CMS 3.0.0-beta.23或更高版本。
为项目做出贡献
如果您想帮助这个项目,请阅读贡献指南
安装
要安装此插件,请按照以下说明操作。
-
打开您的终端并进入Craft项目文件夹
cd /path/to/project -
然后告诉Composer加载插件
composer require itscoding/facebook-connector -
在控制面板中,转到设置 → 插件,并点击FacebookConnector的“安装”按钮。
-
配置插件
配置FacebookConnector
在Facebook上发布条目
添加文件字段config.php并返回一个返回包含您的字段的数组(/path/to/project/fieldconfig.php)
<?php use itscoding\facebookconnector\FacebookConnector; use craft\elements\Entry; return function (Entry $entry) { //you can do some fancy stuff with callables 👍 ! $description = function() use ($entry){ return $entry->teaserSubTitle; }; //callables will not work here! return [ //if true, the message is posted {default:true} 'post_on_facebook' => $entry->post_on_facebook, //official doc https://developers.facebook.com/docs/graph-api/reference/v2.10/post //craft field to get the message to post from {default:''} 'message' => $entry->message, //link to the entry page {default:$entry->getUrl()} 'link' => $entry->getUrl(), //field to get the img url from {default:''} --> no image 'picture' => (count($entry->fb_image) > 0) ? Craft::$app->request->getHostInfo() . $entry->fb_image->first()->getUrl() : '', //field to get the caption from {default:''} 'caption' => $entry->getAuthor()->getName(), //field to get the description from {default:''} 'description' => $description() ]; };
从Facebook获取条目
要从Facebook获取条目,您需要运行一些脚本(如果您需要自动重新加载帖子,请设置cron作业)
#in your project (craft) dir run: php craft facebook-connector/entry-fetch/fetch-list #loads a list with the entries (id, title and content) php craft facebook-connector/entry-fetch/fetch-detail #loads the details for all entries, saved before
请注意,如果详细信息丢失,则条目不完整!(您可以在渲染之前在twig模板中检查条目是否完整)
条目属性
[
'id' => $this->primaryKey(), // like every craft entry
'fbId' => $this->string(255)->unique(),
'dateCreated' => $this->dateTime()->notNull(), // like every craft entry
'dateUpdated' => $this->dateTime()->notNull(), // like every craft entry
'created' => $this->string(255)->notNull(),
'has_detail' => $this->boolean(), // if the entry details are loaded
'type' => $this->string(), // type like ['share','photo','youtube']
'image_src' => $this->string(510), //
'image_height' => $this->string(), //
'image_width' => $this->string(), //
'target' => $this->string(510), // target url from facebook
'url' => $this->string(510), // facebook post url
'internal' => $this->boolean(), // true if the post is from one of the craft pages where the plugin is installed
'uid' => $this->uid(), // like every craft entry
'title' => $this->string(510), // should be clear
'video' => $this->string(510), // [its a link] only set if its a video 'type' (atm. works only wiht youtube
'content' => $this->text() // text body
//event stuff (only when type = event)
'start_time' => $this->string(45),
'end_time' => $this->string(45),
'event_cover_source' => $this->string(255),
'event_cover_offset_x' => $this->string(45),
'event_cover_offset_y' => $this->string(45),
]
示例(行动中)
<div class="col-lg-8 col-md-10 mx-auto"> {% for fbEntry in craft.facebook.getEntries.where('internal = 0').andWhere('type != "event"').limit(3).all %} <div style="position: relative;"> {% if fbEntry.type == 'youtube' %} <h3> {{ fbEntry.title }} </h3> <iframe width="560" height="315" src="https://www.youtube.com/embed{{ fbEntry.video }}?rel=0&controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe> {% else %} <div class="post-preview" style="float: left;width: 70%;"> <h2 class="post-title"> {{ fbEntry.title ?: 'Beitrag vom '~fbEntry.created|date('d.m.y') }} </h2> <p style="padding-bottom: 20px">{{ fbEntry.content }}</p> <p class="post-meta" style="bottom: 0;position: absolute; "> Gepostet auf {% if fbEntry.target %} <a href="{{ fbEntry.target }}" target="_blank"> Facebook</a> {% else %} Facebook {% endif %} {# decode the content, because it was encoded with json to stroe to more types of db's #} am {{ fbEntry.created|date('d.m.y') }} um {{ {{ craft.facebook.decode(fbEntry.content) }} }} </p> </div> <div style="float: left;width: 30%"> {% if fbEntry.image_src %} <img class="img-fluid" src="{{ fbEntry.image_src }}" alt=""> {% endif %} </div> {% endif %} <div style="clear: both"></div> <hr> </div> {% endfor %} </div>
因为我太懒了(我不喜欢编写教程),所以这里有一个youtube链接,其中解释了整个设置过程
feel free to Contribute a written description :)
FacebookConnector 路线图
要完成的事情
-
完成文档
-
添加更多功能 [想法]-[优先级 1=高 5=低]
- 添加选择发布用户的功能 - 5
- 在网站上显示条目上的点赞(和点赞信息) - 4
- 等等。(如果您有想法,请与我联系)