使用表达式引擎创建单事件 ICS 文件

发布于 2024-11-02 21:45:33 字数 484 浏览 0 评论 0原文

我正在尝试基于表达式引擎通道内的单个条目创建 ICAL 文件,但我完成此操作的方法失败了。我尝试过以下操作:

  1. 将条目 ID 传递到新模板(创建文件),但在 EE 中似乎不赞成使用 $_GET 函数
  2. 使用以下命令创建会话变量条目 ID,但似乎无法将此变量添加到 {exp} 查询中:

    {exp:channel:entries channel="gallery" entry_id="MY_PHP_VARIABLE" limit="1" show_future_entries="yes"}

我还没有尝试在每次使用 fwrite() 访问单个条目页面时创建一个平面文件并直接链接到它,但这似乎是一个代价高昂的举动。

PHP 有没有办法在我单击按钮时生成文件?也许会触发页面中编写的函数,这样我就不需要传递或检测 entry_id

I'm trying to create an ICAL file based on a single entry inside an Expression Engine channel but my methods of accomplishing this are failing. I've tried the following:

  1. Passing the entry ID into a new template (which creates the file) but using the $_GET function seems to be frowned upon in EE
  2. Creating a session variable with the entry ID but there seems to be no way of adding this variable to the {exp} query:

    {exp:channel:entries channel="gallery" entry_id="MY_PHP_VARIABLE" limit="1" show_future_entries="yes"}

I haven't tried just making a flat file each time the single entry page is accessed with fwrite() and linking directly to it, but that seems like a costly move.

Is there a way with PHP to make the file when I click a button? Maybe firing off a function written in the page so I don't need to pass or detect the entry_id?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贵在坚持 2024-11-09 21:45:33

我之前已经使用在输出上启用 PHP 的常规模板完成了此操作。

因此,您的 iCal 链接将是 /events/ical/{entry_id},您的 events.group/ical.html 模板将如下所示:

{exp:channel:entries channel="events" sort="asc" show_future_entries="yes" limit="1" require_entry="yes" disable="member_data|categories|pagination"}
<?php
header('Content-type: text/calendar');
header('Content-Disposition: attachment; filename="event-{entry_date format="%Y-%m-%d"}.ics"');
?>
BEGIN:VCALENDAR
PRODID:MY GREAT EVENTS
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
SUMMARY;CHARSET={charset}:{summary}
DESCRIPTION;CHARSET={charset}:{description}
LOCATION;CHARSET={charset}:{venue}, {address}
UID:{entry_date format="%Y%m%d"}-{entry_id}@mydomain.com
URL:{permalink="events/detail"}
DTSTART;VALUE=DATE:{entry_date format="%Y%m%d"}
DTSTAMP:{entry_date format="%Y%m%d"}T000000Z
END:VEVENT
END:VCALENDAR
{/exp:channel:entries}

当然,详细信息可能会有所不同,取决于您是否使用日期字段的时间部分,或专用时间字段等,但您明白了。

I've done this before with a regular template with PHP enabled on output.

So your iCal link would be /events/ical/{entry_id}, and your events.group/ical.html template would look something like:

{exp:channel:entries channel="events" sort="asc" show_future_entries="yes" limit="1" require_entry="yes" disable="member_data|categories|pagination"}
<?php
header('Content-type: text/calendar');
header('Content-Disposition: attachment; filename="event-{entry_date format="%Y-%m-%d"}.ics"');
?>
BEGIN:VCALENDAR
PRODID:MY GREAT EVENTS
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
SUMMARY;CHARSET={charset}:{summary}
DESCRIPTION;CHARSET={charset}:{description}
LOCATION;CHARSET={charset}:{venue}, {address}
UID:{entry_date format="%Y%m%d"}-{entry_id}@mydomain.com
URL:{permalink="events/detail"}
DTSTART;VALUE=DATE:{entry_date format="%Y%m%d"}
DTSTAMP:{entry_date format="%Y%m%d"}T000000Z
END:VEVENT
END:VCALENDAR
{/exp:channel:entries}

The details may vary of course, depending on whether you're using the time portion of your date fields, or a dedicated time field, etc, but you get the idea.

初与友歌 2024-11-09 21:45:33

不确定您是否仍然需要这个,但我需要完全相同的东西并编写了一个插件来处理它。

https://github.com/expressodev/easy_icalendar

基本上,用法只是围绕标准通道条目标签,所以看起来像这样

{exp:easy_ical:calendar timezone="Pacific/Auckland" name="My Easy Event Calendar"}
    {exp:channel:entries channel="events" show_future_entries="yes" show_expired="yes" limit="20"}
        {exp:easy_ical:event uid="{entry_id}" start_time="{entry_date}" end_time="{expiration_date}" location="{event_location}" summary="{title}"}
            {event_description}
        {/exp:easy_ical:event}
    {/exp:channel:entries}
{/exp:easy_ical:calendar}

您可以使用它在单击按钮时显示单个条目。只需创建一个名为 /events/ical 或其他名称的新模板,并使用 url /events/ical/url-title (或entry_id)引用它。

然后在您的频道条目循环中,使用标准

{exp:channel:entries channel="events" url_title="{segment_3}"}

Easy iCal 将生成一个有效的、可下载的 ics 文件。如果您希望链接具有*.ics扩展名(有些读者很挑剔),请将entry_id放在段3中,将文件名放在段4中:

<a href="/events/ical/{entry_id}/{url_title}.ics">

然后只需在您的ical模板中使用entry_id,并忽略段4

Not sure if you still need this, but I needed the exact same thing and wrote a plugin to handle it.

https://github.com/expressodev/easy_icalendar

Basically, the usage just revolves around a standard channel entries tag, so looks something like this

{exp:easy_ical:calendar timezone="Pacific/Auckland" name="My Easy Event Calendar"}
    {exp:channel:entries channel="events" show_future_entries="yes" show_expired="yes" limit="20"}
        {exp:easy_ical:event uid="{entry_id}" start_time="{entry_date}" end_time="{expiration_date}" location="{event_location}" summary="{title}"}
            {event_description}
        {/exp:easy_ical:event}
    {/exp:channel:entries}
{/exp:easy_ical:calendar}

You can use it to show a single entry when you click a button. Just make a new template called /events/ical or something, and reference it using the url /events/ical/url-title (or entry_id).

Then in your channel entries loop, use the standard

{exp:channel:entries channel="events" url_title="{segment_3}"}

Easy iCal will spit out a valid, downloadable ics file. If you want the link to have an *.ics extension (some readers are fussy), put the entry_id in segment 3, and the file name in segment 4:

<a href="/events/ical/{entry_id}/{url_title}.ics">

Then just use the entry_id in your ical template, and ignore segment 4

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文