承接 psmb/newsletter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

psmb/newsletter

Composer 安装命令:

composer require psmb/newsletter

包简介

Generate Newsletters based on Fusion

README 文档

README

With this package you can generate newsletters based on content of your Neos CMS website (e.g. digest of latest articles).

The cool part is that you render those newsletters using Fusion, which allows you to reuse any of your existing website Fusion objects and be completely flexible.

Installation

composer require "psmb/newsletter:@dev"

Configuration

Put something like this into your Settings.yaml:

Psmb:
  Newsletter:
    globalSettings:
      senderAddress: 'robot@server.com'
      senderName: 'Your robot'
    subscriptions:
      -
        identifier: daily
        renderer: 'Your.NameSpace:DailyLetterRenderer'
        label: 'Our daily newsletter'
        interval: P1D
      -
        identifier: weekly
        renderer: 'Your.NameSpace:WeeklyLetterRenderer'
        label: 'Our weekly newsletter (In Russian)'
        interval: P1W
        dimensions:
          language: ['ru']
      -
        identifier: handcrafted
        renderer: 'Your.NameSpace:HandcraftedDigestRenderer'
        sendFromUiNodeType: 'Your.NameSpace:HandcraftedDigest'
        label: 'Manually crafted newsletter'
        interval: manual

You also have to configure a baseUri in your Settings.yaml

Neos:
  Flow:
    http:
      baseUri: 'http://yourdomain.tld/'

Define as many subscription types under Psmb.Newsletter.subscriptions as you need.

setting key description
identifier Identifier of the subscription
renderer Fusion object that would be used for rendering emails sent to this subscription. Defaults to Psmb.Newsletter:MailRenderer. Must inherit from it.
sendFromUiNodeType Show this subscription for the nodes of given nodetype when sending from UI.
interval Time interval identifier that would be used for selecting subscriptions. Can be used for cron jobs. Those marked as manual would appear as options when sending from the UI. Optional.
senderName, senderAddress Override options from globalSettings.
dimensions Array of dimensions in form of "dimensionName: ['dimensionValues']". Falls back to default dimension values.

Also you may need to configure SwiftMailer, see its docs how to do that.

Rendering newsletters

As said before, we render letters purely in Fusion, so it's completely up to you to define the rendering objects. Entry point to rendering is newsletter = Psmb.Newsletter:SubscriptionCase, so you may hook straight into Psmb.Newsletter:SubscriptionCase to intercept the rendering process. But the intended usage is to provide a different renderer per each subscription preset via the renderer setting key (see above).

Then define a Fusion object like this for each renderer:

prototype(Your.NameSpace:WeeklyLetterRenderer) < prototype(Psmb.Newsletter:MailRenderer) {
	subject = 'Our weekly digest'
	body = 'Generate message body. Use your imagination.'

  # You may automatically inline all css styles.
	# body.@process.cssToInline = Psmb.Newsletter:CssToInline {
	#	  cssPath = 'resource://Your.Package/Public/Path/To/Your/Styles.css'
	# }
  # # You may also override these settings, but usually no need to
  # format = 'plaintext' # defaults to 'html'
	# recipientAddress = ${subscriber.email}
	# recipientName = ${subscriber.name}
	# replyToAddress = ${subscription.senderAddress || globalSettings.senderAddress}
	# senderAddress = ${subscription.senderAddress || globalSettings.senderAddress}
	# senderName = ${subscription.senderName || globalSettings.senderName}
}

You'd have the following context variables available:

Context variable name Description
site,documentNode,node All point to site root node.
subscriber Subscriber object. Has name and email keys.
subscription Settings array for current subscription. interval key may be the most interesting one for generating lists of latest articles for given period.
globalSettings Global settings array.
activationLink Only available when generating email confirmation letters.

A more practical example:

prototype(Sfi.Site:DigestMail) < prototype(Psmb.Newsletter:MailRenderer) {
    # ElasticSearch used here, but could be a simple FlowQuery as well
    @context.nodes = ${Search.query(site).nodeType('Sfi.Site:News').exactMatch('type', 'ourNews').greaterThan('date', Date.format(Date.subtract(Date.now(), subscription.interval), "Y-m-d\TH:i:sP")).sortDesc('date').execute()}
    @if.notEmpty = ${q(nodes).count() > 0}
    subject = ${Translation.translate('newsletter.digestSubject', null, [], null, 'Sfi.Site')}
    body = Neos.Fusion:Collection {
        collection = ${nodes}
        itemName = 'node'
        itemRenderer = Sfi.Site:DigestArticle
    }
    @process.cssToInline = Psmb.Newsletter:CssToInline {
        cssPath = 'resource://Sfi.Site/Public/built/index.css'
    }
}

prototype(Sfi.Site:DigestArticle) < prototype(Neos.Fusion:Tag) {
    tagName = 'a'
    attributes.href = NodeUri {
        node = ${node}
        absolute = ${true}
    }
    content = ${node.properties.title}
}

Provided Fusion objects

Object name Description
Psmb.Newsletter:MailRenderer Abstract mail renderer. Returns a RawArray of body, subject and other mail options passed to swiftmailer. See above for details.
Psmb.Newsletter:EditSubscriptionLink Generated a link to edit action of the plugin
Psmb.Newsletter:UnsubscribeLink Generated a link to unsubscribe action of the plugin
Psmb.Newsletter:CssToInline Processor to automatically inline CSS styles
Psmb.Newsletter:SubscriptionCase Rendering entry point. Usually no need to touch this one
Psmb.Newsletter:SubscriptionPlugin Configured Neos.Neos:Plugin instance that insert Flow signup plugin.

To customize the confirmation mail, override Psmb.Newsletter:ConfirmationMailRenderer.

Rendering signup plugin

Insert Psmb.Newsletter:SubscriptionPlugin nodetype or render it manually.

Subscription has the following flow:

  1. Fill in the sign up form. Asks for name, and email, and allows to choose between available subscription plans.
  2. Confirm email.
  3. Edit subscription options or unsubscribe from email links.

You absolutely have to override the default templates, the default ones are there just for demo purpose. Create a Views.yaml file in Configuration:

-
  requestFilter: 'isPackage("Psmb.Newsletter") && isController("Subscription")'
  options:
    templateRootPaths:
      - 'resource://Sfi.Site/Private/Newsletter/Templates/'
      - 'resource://Psmb.Newsletter/Private/Templates'
    partialRootPaths:
      - 'resource://Sfi.Site/Private/Newsletter/Partials/'
      - 'resource://Psmb.Newsletter/Private/Partials/'
    layoutRootPaths:
      - 'resource://Sfi.Site/Private/Newsletter/Layouts/'

Sending things out

Once you are ready setting up rendering of your subscriptions, it's time to send the out! There's a CLI command for it.

./flow newsletter:send --subscription="daily" would send out newsletter to all users subscribed to subscription with identifier "daily".

./flow newsletter:send --interval="P1H" would find all subscriptions with interval equal to "P1H" and send out letters to them. This is useful for setting up cron tasks based on time interval.

Manual sending from the UI

image

If your nodetype inherits from Psmb.Newsletter:NewsletterMixin you would see a new inspector tab from which you would be able to send manual newsletters, based on the current document node.

For this to work, one or more of your subscription presets must have interval: manual. Those presets would appear in the inspector view selectbox. Click send, and the newsletter would be send out to all subscribers of the chosen subscription group. Current document node would be available in the Fusion renderer as documentNode and node.

Improving reliabillity with job queue

This package uses flowpack/jobqueue package to generate and deliver messages. Refer to its docs how to improve its reliabillity via proper job queue implementations.

Importing subscribers from CSV

Create a CSV file with your subscribers data and put it somewhere on your server.

The file should have the following format:

"user@email.com","User Name","subscriptionId1|subscriptionId2"
"user1@email.com","User1 Name","subscriptionId2"

Then run (file path is relative to installation root):

./flow newsletter:importCsv --filename="test.csv"

Here's a quick example how to create CSV exports from mysql:

SELECT email, name INTO OUTFILE '/path/test.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM yourTable;

External Datasources

The default datasource for fetching subscribers has an identifier Repository. It fetches all subscribers subscribed via the default subscription plugin.

You may fetch subscribers from an external JSON source via the Json datasource. Here's an example:

Psmb:
  Newsletter:
    subscriptions:
      -
        dataSourceIdentifier: 'Json'
        dataSourceOptions:
          uri: 'http://some.host/some-url'

Alternatively you may provide your custom datasources. See implementation of JsonDataSource.php to see how to do that.

It is also possible to provide some additional arguments for the datasource that would be filled from other properties of a node. Here is an example NodeTypes.yaml for this:

'Psmb.Newsletter:NewsletterMixin':
  abstract: true
  ui:
    inspector:
      tabs:
        newsletter:
          label: i18n
          position: 100
          icon: icon-send
      groups:
        newsletter:
          label: i18n
          tab: newsletter
      views:
        newsletter:
          viewOptions:
            dataSourceAdditionalArguments:
              sampleArgument: 'ClientEval:node.properties.sampleProperty'
  properties:
    sampleProperty:
      type: DateTime
      ui:
        label: 'Subscribers since'
        inspector:
          group: newsletter
          position: 1
          editorOptions:
            format: 'Y-m-d'

Then the dataSourceAdditionalArguments would be passed to a datasource. You may check out how Json datasource handles it.

Acknowledgements

This is my first Flow package, and it wouldn't have been possible without a support of the community by answering dozens of n00b questions on Slack, by Christian Müller in particular.

psmb/newsletter 适用场景与选型建议

psmb/newsletter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.46k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2016 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 psmb/newsletter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 psmb/newsletter 我们能提供哪些服务?
定制开发 / 二次开发

基于 psmb/newsletter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 4
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2016-12-06