Compare commits
2 Commits
v0.5.6
...
loop-build
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d15dce1e84 | ||
|
|
db4747d85f |
27
.gitea/workflows/loop-builder-release.yml
Normal file
27
.gitea/workflows/loop-builder-release.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
name: Loop Builder release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'loop-builder-v*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the tagged source
|
||||
env:
|
||||
TAG: ${{ gitea.ref_name }}
|
||||
COMMIT: ${{ gitea.sha }}
|
||||
run: |
|
||||
git clone --depth 1 --branch "$TAG" https://git.labs.casa/josh/eventLabs.git source
|
||||
test "$(git -C source rev-parse HEAD)" = "$(git -C source rev-parse "$COMMIT^{commit}")"
|
||||
- name: Publish the Loop Builder ZIP
|
||||
working-directory: source
|
||||
env:
|
||||
TAG: ${{ gitea.ref_name }}
|
||||
EVENTLABS_RELEASE_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: python3 scripts/release.py --loop-builder "$TAG" --publish
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Publish an events calendar, design single-event pages in Elementor, and sync club events from burnWorks. eventLabs manages schedules, venues, organizers, and series in WordPress and provides its own versioned REST API.
|
||||
|
||||
[Download the latest release](https://git.labs.casa/josh/eventLabs/releases/latest) · [API reference](docs/API.md) · [Release guide](docs/RELEASING.md)
|
||||
[Download the latest release](https://git.labs.casa/josh/eventLabs/releases/latest) · [Migration guide](docs/MIGRATION.md) · [API reference](docs/API.md) · [Release guide](docs/RELEASING.md)
|
||||
|
||||

|
||||
|
||||
@@ -20,10 +20,11 @@ Starting with **0.5.2**, the active plugin checks Gitea for stable releases and
|
||||
## Calendar and publishing
|
||||
|
||||
- **Calendar views** include List, Month, Week, Day, Photo, Map, and Summary. In Month and Week, multi-day bars span their dates and show event previews on hover and keyboard focus. Set a custom color under **Events → Event Categories**.
|
||||
- **Event Loop Builder** is a separate add-on for Elementor. Browse 36 editable designs in **Events → Loop Presets**, manage copies under **Events → Loop Templates**, and display events with the **Event Loop** widget. [Install and use the add-on](addons/eventlabs-loop-builder/README.md) · [Download Loop Builder](https://git.labs.casa/josh/eventLabs/releases/tag/loop-builder-v0.2.0)
|
||||
- **Schedules** support all-day and timed events, daily through yearly recurrence, additional dates, and exclusions. Link multiple venues and organizers and group related events into series.
|
||||
- **Maps** load on single events with mapped venues when enabled. The calendar Map view groups events into pins by location and filters them by date range. Save a Geoapify key and enable OpenStreetMap maps under **Events → Settings**.
|
||||
- **Community submissions** use `[burn_events_submit]` and `[burn_events_mine]`. Submitted events enter Pending Review.
|
||||
- **Imports and migration** are under **Events → Import and Export**. Upload CSV or iCalendar files, or review a detected The Events Calendar migration. The migration copies drafts with their saved occurrence dates and linked records.
|
||||
- **Imports and migration** are under **Events → Import and Export**. The Events Calendar migration copies events as drafts with their saved occurrence dates and linked records. Choose a Single Event Template before copying, or apply one to events already copied. Follow the [migration guide](docs/MIGRATION.md) to review and publish the results. The same screen accepts CSV and iCalendar files.
|
||||
|
||||

|
||||
|
||||
|
||||
43
addons/eventlabs-loop-builder/README.md
Normal file
43
addons/eventlabs-loop-builder/README.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# eventLabs Loop Builder
|
||||
|
||||
Design a reusable event card in Elementor and display it in a grid, list, or carousel. Each card uses the schedule and link for the occurrence it represents.
|
||||
|
||||
## Install the add-on
|
||||
|
||||
1. Activate **eventLabs 0.5.8 or later** and **Elementor 3.27 or later**. Elementor Free supports the card builder and Event Loop widget.
|
||||
2. Download the add-on ZIP from the [eventLabs Loop Builder release](https://git.labs.casa/josh/eventLabs/releases/tag/loop-builder-v0.2.0).
|
||||
3. In WordPress, open **Plugins → Add Plugin → Upload Plugin** and choose the `eventlabs-loop-builder` ZIP. If the add-on is already installed, choose **Replace current with uploaded**.
|
||||
4. Activate **eventLabs Loop Builder**. Its screens appear under **Events**.
|
||||
|
||||
## Choose and edit a preset
|
||||
|
||||
1. Open **Events → Loop Presets**. Browse 36 styles, with four designs in each Classic, Minimal, or Modern grid, list, and carousel family. Use the **Layout** and **Style** filters to narrow the library.
|
||||
2. Click **Use preset** to create a draft in Elementor. Or select a built-in preset directly in the **Event Loop** widget to use it as designed.
|
||||
3. Rearrange the containers and add **Loop Event Field** widgets from the **eventLabs** category. Choose from the title, featured image, schedule, date badge, venue and address, venue map, organizers, series, excerpt, categories, tags, cost, status, event link, website, share actions, and eventLabs custom fields.
|
||||
4. To preview a particular event, open the template’s WordPress editor under **Events → Loop Templates**, set **Preview event ID**, and save. Choose a recent published event from the suggestions or enter an ID from the event’s edit URL. A blank field previews the next available event.
|
||||
5. Publish the template in Elementor. The **Layout** column under **Events → Loop Templates** shows its recommended display. Use the **Duplicate** row action to make a new editable draft from an existing template.
|
||||
|
||||
## Display a loop
|
||||
|
||||
1. Edit an Elementor page and drag in **Event Loop** from the **eventLabs** category.
|
||||
2. Under **Layout → Loop template**, choose a built-in preset or a published template. **Use template layout** selects the preset’s grid, list, or carousel layout automatically. You can also choose a display manually. Set responsive columns and card spacing, toggle equal card heights, or group a list by month.
|
||||
3. In **Event query**, choose a relative period, a date range, upcoming and ongoing events, past events, or all dates. Date ranges include occurrences that overlap the dates in the site’s time zone. **Through date** includes the full day. Leave one date blank for an open-ended range.
|
||||
4. Combine categories, tags, venues, organizers, series, cities, countries, keywords, featured status, and a burnWorks club or sub-club. Multiple values in one field match any selected value. Different fields narrow the same results. City and country use saved venue addresses. Set the date order, occurrence offset, page size, and empty message as needed.
|
||||
5. Under **Filter bar**, choose which search and filter controls visitors can use. Visitor selections narrow the results allowed by the page editor. Each widget keeps its own filter and pagination state.
|
||||
6. Under **Pagination**, choose **Page links**, **Load more**, or **None**. Load more appends the next page in place and also works as a regular link when JavaScript is unavailable.
|
||||
7. For a carousel, choose arrows, a dot, fraction, or progress indicator, slides per move, the focus effect, and wrapping at the ends. Autoplay is optional, pauses on hover and when keyboard focus enters the carousel, and respects reduced-motion settings.
|
||||
8. Publish the page and check desktop and mobile. Open a recurring event card to verify it links to the displayed occurrence.
|
||||
|
||||
When a widget renders in an event category, venue, organizer, series, or events archive, **Current event archive** uses that context. When it renders on an event page, **Related to the current event** uses shared categories and excludes the event being viewed. Use **Select filters below** for ordinary pages.
|
||||
|
||||
## Troubleshoot
|
||||
|
||||
- If the menu is missing, confirm both dependencies and the add-on are active. Use an account that can edit theme options, such as a WordPress administrator.
|
||||
- If a saved layout is missing from **Loop template**, publish it in Elementor, then reload the page editor.
|
||||
- If the loop is empty, try the **Built-in event card** and the default date query. Confirm the events are published and show on the eventLabs calendar.
|
||||
- Venue maps use the eventLabs map setting and saved venue coordinates.
|
||||
- Loop Templates style cards inside the Event Loop widget. Manage individual event pages through **Events → Single Event Templates**.
|
||||
|
||||
## Build the ZIP
|
||||
|
||||
From the eventLabs repository root, run `python3 scripts/release.py --loop-builder` after committing the source. See the [release guide](../../docs/RELEASING.md) for the tag and publishing workflow.
|
||||
80
addons/eventlabs-loop-builder/assets/library.css
Normal file
80
addons/eventlabs-loop-builder/assets/library.css
Normal file
@@ -0,0 +1,80 @@
|
||||
.ell-library {
|
||||
max-inline-size: 96rem;
|
||||
}
|
||||
|
||||
.ell-library-toolbar,
|
||||
.ell-library-filters {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: .55rem;
|
||||
}
|
||||
|
||||
.ell-library-toolbar {
|
||||
justify-content: space-between;
|
||||
margin-block: 1.15rem .8rem;
|
||||
}
|
||||
|
||||
.ell-library-filters label {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ell-library-count {
|
||||
color: #465765;
|
||||
}
|
||||
|
||||
.ell-library-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(min(100%, 21rem), 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.ell-library-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-inline-size: 0;
|
||||
border: 1px solid #d7e1e6;
|
||||
border-radius: .8rem;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.ell-library .ell-preset-preview {
|
||||
display: grid;
|
||||
align-items: center;
|
||||
min-block-size: 20rem;
|
||||
padding: 1rem;
|
||||
border-block-end: 1px solid #d7e1e6;
|
||||
border-start-start-radius: inherit;
|
||||
border-start-end-radius: inherit;
|
||||
background: #eef3f6;
|
||||
}
|
||||
|
||||
.ell-library .ell-preset-preview .ell-preset {
|
||||
block-size: auto;
|
||||
}
|
||||
|
||||
.ell-library-details {
|
||||
display: grid;
|
||||
justify-items: start;
|
||||
grid-template-rows: auto auto 1fr auto;
|
||||
flex: 1;
|
||||
gap: .4rem;
|
||||
padding: .95rem 1rem 1rem;
|
||||
}
|
||||
|
||||
.ell-library-details :is(p, h2) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ell-library-type {
|
||||
color: #305c6a;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.ell-library-description {
|
||||
color: #465765;
|
||||
}
|
||||
|
||||
.ell-library-details form {
|
||||
margin-block-start: .4rem;
|
||||
}
|
||||
552
addons/eventlabs-loop-builder/assets/loop.css
Normal file
552
addons/eventlabs-loop-builder/assets/loop.css
Normal file
@@ -0,0 +1,552 @@
|
||||
.ell-loop {
|
||||
--ell-columns: 3;
|
||||
--ell-gap: 1.35rem;
|
||||
--ell-ink: #172a33;
|
||||
--ell-muted: #4d636e;
|
||||
--ell-line: #d6e2e5;
|
||||
--ell-accent: #125861;
|
||||
--ell-accent-soft: #e5f2f2;
|
||||
--ell-focus: #156c78;
|
||||
color: var(--ell-ink);
|
||||
container-type: inline-size;
|
||||
inline-size: 100%;
|
||||
min-inline-size: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.ell-loop { --ell-columns: 2; }
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.ell-loop { --ell-columns: 1; }
|
||||
}
|
||||
|
||||
.ell-items {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(var(--ell-columns), minmax(0, 1fr));
|
||||
gap: var(--ell-gap);
|
||||
min-inline-size: 0;
|
||||
}
|
||||
|
||||
.ell-layout-list > .ell-items {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.ell-item {
|
||||
min-inline-size: 0;
|
||||
}
|
||||
|
||||
.ell-item > .elementor {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
block-size: 100%;
|
||||
}
|
||||
|
||||
.ell-layout-carousel > .ell-items {
|
||||
grid-template-columns: none;
|
||||
grid-auto-flow: column;
|
||||
grid-auto-columns: calc((100% - (var(--ell-columns) - 1) * var(--ell-gap)) / var(--ell-columns));
|
||||
overflow-x: auto;
|
||||
scroll-snap-type: inline mandatory;
|
||||
scrollbar-color: #96b3ba transparent;
|
||||
scrollbar-width: thin;
|
||||
padding-block: 4px 10px;
|
||||
}
|
||||
|
||||
.ell-layout-carousel .ell-item {
|
||||
scroll-snap-align: start;
|
||||
}
|
||||
|
||||
.ell-carousel-controls {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: .5rem;
|
||||
margin-block-end: .5rem;
|
||||
}
|
||||
|
||||
.ell-carousel-controls[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ell-loop .ell-carousel-controls .ell-nav-button {
|
||||
padding: 0;
|
||||
min-inline-size: 2.65rem;
|
||||
min-block-size: 2.65rem;
|
||||
font-size: 1.3rem;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.ell-carousel-controls:dir(rtl) .ell-nav-button span {
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
|
||||
.ell-carousel-controls .ell-nav-button:disabled {
|
||||
opacity: .45;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.ell-pagination {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
gap: .7rem;
|
||||
margin-block-start: 1.4rem;
|
||||
}
|
||||
|
||||
.ell-loop .ell-nav-button {
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid var(--ell-line);
|
||||
border-radius: .6rem;
|
||||
background: #fff;
|
||||
color: var(--ell-accent);
|
||||
font: 650 .9rem/1.3 Inter, system-ui, sans-serif;
|
||||
padding: .65rem 1rem;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.ell-loop .ell-nav-button:where(:hover, :focus-visible):not(:disabled) {
|
||||
background: var(--ell-accent-soft);
|
||||
color: var(--ell-accent);
|
||||
}
|
||||
|
||||
.ell-loop :is(a, button, input, select, .ell-items):focus-visible,
|
||||
.ell-starter a:focus-visible {
|
||||
outline: 2px solid var(--ell-focus, #156c78);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
.ell-page {
|
||||
color: var(--ell-muted);
|
||||
font: 550 .9rem/1.4 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-starter {
|
||||
display: flex;
|
||||
flex: 1 1 auto;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
min-block-size: 100%;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid var(--ell-line, #d6e2e5);
|
||||
border-radius: 1.05rem;
|
||||
background: #fff;
|
||||
color: var(--ell-ink, #172a33);
|
||||
}
|
||||
|
||||
.ell-starter.e-con,
|
||||
.ell-starter :is(.ell-starter-media, .ell-starter-meta).e-con {
|
||||
--padding-top: 0px;
|
||||
--padding-right: 0px;
|
||||
--padding-bottom: 0px;
|
||||
--padding-left: 0px;
|
||||
}
|
||||
|
||||
.ell-starter.e-con {
|
||||
--flex-grow: 1;
|
||||
--row-gap: 0px;
|
||||
--column-gap: 0px;
|
||||
}
|
||||
|
||||
body.single-eventlabs_loop_item .ell-starter {
|
||||
max-inline-size: 36rem;
|
||||
margin-inline: auto;
|
||||
}
|
||||
|
||||
.ell-starter-media {
|
||||
position: relative;
|
||||
display: grid;
|
||||
place-items: stretch;
|
||||
aspect-ratio: 16 / 10;
|
||||
overflow: hidden;
|
||||
background: #143c45;
|
||||
}
|
||||
|
||||
.ell-starter-media :is(.elementor-widget, .elementor-widget-container, .ell-image) {
|
||||
block-size: 100%;
|
||||
}
|
||||
|
||||
.ell-starter-media img {
|
||||
display: block;
|
||||
inline-size: 100%;
|
||||
block-size: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.ell-image {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ell-image-placeholder {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
block-size: 100%;
|
||||
min-block-size: 5.75rem;
|
||||
padding: 1rem;
|
||||
background: linear-gradient(140deg, #123d47, #265a65 60%, #506d80);
|
||||
color: #fff;
|
||||
font: 650 clamp(1.6rem, 6vw, 3.15rem)/1 Inter, system-ui, sans-serif;
|
||||
letter-spacing: -.045em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ell-starter-body {
|
||||
--ell-card-padding: clamp(1.05rem, 3vw, 1.5rem);
|
||||
display: flex;
|
||||
flex: 1 1 auto;
|
||||
flex-direction: column;
|
||||
gap: .56rem;
|
||||
padding: var(--ell-card-padding);
|
||||
}
|
||||
|
||||
.ell-starter .ell-starter-body.e-con {
|
||||
--flex-grow: 1;
|
||||
--padding-top: var(--ell-card-padding);
|
||||
--padding-right: var(--ell-card-padding);
|
||||
--padding-bottom: var(--ell-card-padding);
|
||||
--padding-left: var(--ell-card-padding);
|
||||
--row-gap: .56rem;
|
||||
--column-gap: .56rem;
|
||||
}
|
||||
|
||||
.ell-starter-body > .ell-link:last-child,
|
||||
.ell-starter .ell-starter-body > .elementor-widget:last-child:has(.ell-link) {
|
||||
margin-block-start: auto;
|
||||
}
|
||||
|
||||
.ell-starter-compact {
|
||||
border-inline-start: 4px solid var(--ell-accent, #125861);
|
||||
}
|
||||
|
||||
.ell-starter .ell-starter-meta {
|
||||
--flex-direction: row;
|
||||
--flex-wrap: wrap;
|
||||
--justify-content: flex-start;
|
||||
--align-items: center;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
gap: .55rem;
|
||||
}
|
||||
|
||||
.ell-starter .ell-starter-meta > .elementor-widget {
|
||||
--container-widget-width: auto;
|
||||
flex: 0 0 auto;
|
||||
inline-size: auto;
|
||||
}
|
||||
|
||||
.ell-starter :is(.elementor-widget, .elementor-widget-container) {
|
||||
margin-block: 0;
|
||||
}
|
||||
|
||||
.ell-starter :is(.ell-field, .ell-field-placeholder) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ell-starter .ell-title {
|
||||
color: var(--ell-ink, #172a33);
|
||||
font: 710 clamp(1.28rem, 2.2vw, 1.85rem)/1.17 Inter, system-ui, sans-serif;
|
||||
letter-spacing: -.032em;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.ell-starter .ell-title a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.ell-starter .ell-title a:hover {
|
||||
color: var(--ell-accent, #125861);
|
||||
text-decoration: underline;
|
||||
text-underline-offset: .14em;
|
||||
}
|
||||
|
||||
.ell-starter .ell-schedule {
|
||||
display: block;
|
||||
color: var(--ell-accent, #125861);
|
||||
font: 660 .83rem/1.4 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-starter :is(.ell-venue, .ell-excerpt) {
|
||||
color: var(--ell-muted, #4d636e);
|
||||
font: 430 .93rem/1.5 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-starter .ell-venue {
|
||||
font-weight: 620;
|
||||
}
|
||||
|
||||
.ell-starter .ell-excerpt {
|
||||
margin-block: .15rem .25rem;
|
||||
}
|
||||
|
||||
.ell-categories, .ell-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: .35rem;
|
||||
}
|
||||
|
||||
.ell-chip, .ell-status {
|
||||
display: inline-block;
|
||||
align-self: flex-start;
|
||||
border-radius: .45rem;
|
||||
padding: .18rem .5rem;
|
||||
background: var(--ell-accent-soft, #e5f2f2);
|
||||
color: var(--ell-accent, #125861);
|
||||
font: 650 .74rem/1.45 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-starter .ell-cost {
|
||||
color: var(--ell-ink, #172a33);
|
||||
font: 670 .9rem/1.4 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-starter .ell-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
align-self: flex-start;
|
||||
border-radius: .55rem;
|
||||
padding: .53rem .85rem;
|
||||
background: var(--ell-accent, #125861);
|
||||
color: #fff;
|
||||
font: 650 .85rem/1.4 Inter, system-ui, sans-serif;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.ell-starter .ell-link:hover {
|
||||
background: #0a424b;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.ell-item .elementor-widget-eventlabs-loop-field:not(:has(.ell-field, .ell-field-placeholder)),
|
||||
.ell-item .ell-starter-meta:not(:has(.ell-field, .ell-field-placeholder)) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@container (min-width: 38rem) {
|
||||
.ell-layout-list .ell-starter-photo {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(10rem, 30%) minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.ell-layout-list .ell-starter-media {
|
||||
aspect-ratio: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.ell-field-placeholder, .ell-empty {
|
||||
padding: .9rem 1rem;
|
||||
border: 1px dashed var(--ell-line, #d6e2e5);
|
||||
border-radius: .6rem;
|
||||
color: var(--ell-muted, #4d636e);
|
||||
font: 500 .93rem/1.45 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-loop .el-loop-filters {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
flex-wrap: wrap;
|
||||
gap: .75rem;
|
||||
margin-block: 0 1.25rem;
|
||||
}
|
||||
|
||||
.ell-loop .el-loop-filter-field {
|
||||
display: flex;
|
||||
flex: 1 1 11rem;
|
||||
flex-direction: column;
|
||||
gap: .3rem;
|
||||
font: 620 .83rem/1.4 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-loop .el-loop-filter-field label {
|
||||
color: var(--ell-ink);
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.ell-loop .el-loop-filter-field :is(input, select) {
|
||||
box-sizing: border-box;
|
||||
inline-size: 100%;
|
||||
min-block-size: 2.7rem;
|
||||
padding: .55rem .75rem;
|
||||
border: 1px solid var(--ell-line);
|
||||
border-radius: .6rem;
|
||||
background-color: #fff;
|
||||
color: var(--ell-ink);
|
||||
font: 450 .94rem/1.4 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-loop .el-loop-filter-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .65rem;
|
||||
}
|
||||
|
||||
.ell-loop .el-loop-filter-actions button {
|
||||
min-block-size: 2.7rem;
|
||||
border: 1px solid var(--ell-accent);
|
||||
border-radius: .6rem;
|
||||
padding: .5rem .8rem;
|
||||
background: var(--ell-accent);
|
||||
color: #fff;
|
||||
font: 650 .9rem/1.4 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-loop .el-loop-filter-actions a {
|
||||
color: var(--ell-accent);
|
||||
font: 650 .86rem/1.4 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-natural-height > .ell-items {
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.ell-natural-height .ell-item > .elementor {
|
||||
block-size: auto;
|
||||
}
|
||||
|
||||
.ell-loop .ell-month {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .8rem;
|
||||
margin: .45rem 0 0;
|
||||
color: var(--ell-ink);
|
||||
font: 700 1.16rem/1.25 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-month::after {
|
||||
flex: 1;
|
||||
border-block-end: 1px solid var(--ell-line);
|
||||
content: "";
|
||||
}
|
||||
|
||||
.ell-carousel-controls {
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.ell-loop .ell-carousel-controls .ell-carousel-toggle {
|
||||
padding-inline: .8rem;
|
||||
font-size: .85rem;
|
||||
}
|
||||
|
||||
.ell-carousel-indicator {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: .18rem;
|
||||
margin-inline-end: auto;
|
||||
color: var(--ell-muted);
|
||||
font: 600 .84rem/1.2 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-loop .ell-carousel-dot {
|
||||
position: relative;
|
||||
inline-size: 1.55rem;
|
||||
min-block-size: 1.55rem;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background: transparent;
|
||||
color: var(--ell-accent);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ell-carousel-dot::before {
|
||||
position: absolute;
|
||||
inset: 50% auto auto 50%;
|
||||
inline-size: .48rem;
|
||||
block-size: .48rem;
|
||||
transform: translate(-50%, -50%);
|
||||
border: 1px solid currentColor;
|
||||
border-radius: inherit;
|
||||
content: "";
|
||||
}
|
||||
|
||||
.ell-carousel-dot[aria-current="true"]::before {
|
||||
background: currentColor;
|
||||
}
|
||||
|
||||
.ell-carousel-indicator progress {
|
||||
accent-color: var(--ell-accent);
|
||||
inline-size: 6rem;
|
||||
block-size: .55rem;
|
||||
}
|
||||
|
||||
.ell-focus-effect > .ell-items > .ell-item {
|
||||
opacity: .83;
|
||||
transition: opacity .22s ease;
|
||||
}
|
||||
|
||||
.ell-focus-effect > .ell-items > .ell-item:is(.ell-active, :hover, :focus-within) {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.ell-focus-effect > .ell-items > .ell-item {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
|
||||
.ell-filter-error {
|
||||
flex-basis: 100%;
|
||||
color: #8a2424;
|
||||
}
|
||||
|
||||
.ell-loop .ell-more-status {
|
||||
margin: .6rem 0 0;
|
||||
color: var(--ell-muted);
|
||||
text-align: center;
|
||||
font: 550 .86rem/1.45 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-more-status:empty,
|
||||
.ell-share-status:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ell-loop[aria-busy="true"] .ell-pagination a[rel="next"] {
|
||||
opacity: .64;
|
||||
cursor: progress;
|
||||
}
|
||||
|
||||
.ell-share summary {
|
||||
width: fit-content;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: .2em;
|
||||
}
|
||||
|
||||
.ell-share > div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: .5rem;
|
||||
margin-block-start: .45rem;
|
||||
}
|
||||
|
||||
.ell-share > div > input {
|
||||
box-sizing: border-box;
|
||||
flex: 1 1 100%;
|
||||
min-inline-size: 0;
|
||||
max-inline-size: 100%;
|
||||
}
|
||||
|
||||
.ell-share [data-ell-copy] {
|
||||
border: 1px solid currentColor;
|
||||
border-radius: .35rem;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
padding: .24rem .45rem;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ell-share-status {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
242
addons/eventlabs-loop-builder/assets/loop.js
Normal file
242
addons/eventlabs-loop-builder/assets/loop.js
Normal file
@@ -0,0 +1,242 @@
|
||||
(() => {
|
||||
const initialized = new WeakSet();
|
||||
const motion = window.matchMedia('(prefers-reduced-motion: reduce)');
|
||||
|
||||
function initializeCarousel(root) {
|
||||
if (initialized.has(root)) return;
|
||||
const items = root.querySelector(':scope > .ell-items');
|
||||
const controls = root.querySelector(':scope > .ell-carousel-controls');
|
||||
if (!items || !controls) return;
|
||||
initialized.add(root);
|
||||
|
||||
const previous = controls.querySelector('[data-ell-direction="-1"]');
|
||||
const next = controls.querySelector('[data-ell-direction="1"]');
|
||||
const indicator = controls.querySelector('[data-ell-indicator]');
|
||||
const play = controls.querySelector('[data-ell-play]');
|
||||
const wrap = controls.dataset.ellWrap === '1';
|
||||
const step = Number(controls.dataset.ellStep) || 1;
|
||||
const delay = Number(controls.dataset.ellAutoplay) * 1000;
|
||||
let playing = !!delay && !motion.matches;
|
||||
let hovered = false;
|
||||
let timer;
|
||||
let frame;
|
||||
let positions = [];
|
||||
let active = 0;
|
||||
let dots = [];
|
||||
let progress;
|
||||
|
||||
function inlineDirection() {
|
||||
return getComputedStyle(items).direction === 'rtl' ? -1 : 1;
|
||||
}
|
||||
|
||||
function measure() {
|
||||
const styles = getComputedStyle(items);
|
||||
const gap = parseFloat(styles.columnGap) || 0;
|
||||
const overflow = Math.max(0, items.scrollWidth - items.clientWidth);
|
||||
let offset = 0;
|
||||
positions = [0];
|
||||
for (const card of items.children) {
|
||||
offset += card.getBoundingClientRect().width + gap;
|
||||
const position = Math.min(overflow, offset);
|
||||
if (position - positions[positions.length - 1] < 1) break;
|
||||
positions.push(position);
|
||||
}
|
||||
if (indicator?.dataset.ellIndicator === 'dots' && dots.length !== positions.length) {
|
||||
const restoreFocus = indicator.contains(document.activeElement);
|
||||
indicator.replaceChildren();
|
||||
dots = positions.map((_, index) => {
|
||||
const dot = document.createElement('button');
|
||||
dot.type = 'button';
|
||||
dot.className = 'ell-carousel-dot';
|
||||
dot.setAttribute('aria-label', indicator.dataset.slideLabel.replace('%d', index + 1));
|
||||
dot.addEventListener('click', () => goTo(index));
|
||||
indicator.append(dot);
|
||||
return dot;
|
||||
});
|
||||
if (restoreFocus) dots[Math.min(active, dots.length - 1)]?.focus();
|
||||
}
|
||||
if (indicator?.dataset.ellIndicator === 'progress' && !progress) {
|
||||
progress = document.createElement('progress');
|
||||
progress.setAttribute('aria-label', indicator.getAttribute('aria-label'));
|
||||
indicator.append(progress);
|
||||
}
|
||||
update();
|
||||
restart();
|
||||
}
|
||||
|
||||
function update() {
|
||||
const position = Math.abs(items.scrollLeft);
|
||||
active = positions.reduce((closest, left, index) =>
|
||||
Math.abs(left - position) < Math.abs(positions[closest] - position) ? index : closest, 0);
|
||||
const count = positions.length;
|
||||
controls.hidden = count < 2 || controls.children.length === 0;
|
||||
if (previous) previous.disabled = !wrap && active === 0;
|
||||
if (next) next.disabled = !wrap && active >= count - 1;
|
||||
if (indicator?.dataset.ellIndicator === 'fraction') indicator.textContent = `${active + 1} / ${count}`;
|
||||
if (progress) {
|
||||
progress.max = count;
|
||||
progress.value = active + 1;
|
||||
}
|
||||
dots.forEach((dot, index) => {
|
||||
if (index === active) dot.setAttribute('aria-current', 'true');
|
||||
else dot.removeAttribute('aria-current');
|
||||
});
|
||||
if (root.classList.contains('ell-focus-effect')) {
|
||||
const focused = items.children[active];
|
||||
items.querySelector('.ell-active')?.classList.remove('ell-active');
|
||||
focused?.classList.add('ell-active');
|
||||
}
|
||||
}
|
||||
|
||||
function goTo(index) {
|
||||
const last = positions.length - 1;
|
||||
const target = wrap && index < 0 ? last : wrap && index > last ? 0 : Math.max(0, Math.min(last, index));
|
||||
items.scrollTo({left: inlineDirection() * positions[target], behavior: motion.matches ? 'auto' : 'smooth'});
|
||||
}
|
||||
|
||||
function restart() {
|
||||
window.clearInterval(timer);
|
||||
if (play) play.textContent = playing ? play.dataset.pause : play.dataset.play;
|
||||
if (!playing || hovered || positions.length < 2 || document.hidden || motion.matches) return;
|
||||
timer = window.setInterval(() => {
|
||||
if (!root.isConnected || !playing || hovered || document.hidden || motion.matches) {
|
||||
window.clearInterval(timer);
|
||||
return;
|
||||
}
|
||||
const last = positions.length - 1;
|
||||
if (!wrap && active === last) {
|
||||
playing = false;
|
||||
restart();
|
||||
} else {
|
||||
goTo(active + step);
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
controls.addEventListener('click', (event) => {
|
||||
const arrow = event.target.closest('[data-ell-direction]');
|
||||
if (arrow) goTo(active + step * Number(arrow.dataset.ellDirection));
|
||||
if (event.target.closest('[data-ell-play]')) {
|
||||
playing = !playing && !motion.matches;
|
||||
restart();
|
||||
}
|
||||
});
|
||||
root.addEventListener('pointerenter', () => { hovered = true; restart(); });
|
||||
root.addEventListener('pointerleave', () => { hovered = false; restart(); });
|
||||
root.addEventListener('focusin', (event) => {
|
||||
if (playing && !root.contains(event.relatedTarget)) {
|
||||
playing = false;
|
||||
restart();
|
||||
}
|
||||
});
|
||||
items.addEventListener('scroll', () => {
|
||||
window.cancelAnimationFrame(frame);
|
||||
frame = window.requestAnimationFrame(update);
|
||||
}, {passive: true});
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(items);
|
||||
root.addEventListener('ell:cards-added', measure);
|
||||
measure();
|
||||
}
|
||||
|
||||
function initializeWithin(scope) {
|
||||
scope.querySelectorAll('.ell-layout-carousel').forEach(initializeCarousel);
|
||||
}
|
||||
|
||||
function reinitializeCards(cards) {
|
||||
const elementor = window.elementorFrontend;
|
||||
if (!elementor?.elementsHandler?.runReadyTrigger || !window.jQuery) return;
|
||||
cards.forEach(card => {
|
||||
card.querySelectorAll('.elementor-element').forEach(element => {
|
||||
elementor.elementsHandler.runReadyTrigger(window.jQuery(element));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function loadMore(event) {
|
||||
const link = event.target.closest('[data-ell-more] a[rel="next"]');
|
||||
if (!link || event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || link.dataset.ellFallback) return;
|
||||
const url = new URL(link.href);
|
||||
const root = link.closest('.ell-loop');
|
||||
const items = root?.querySelector(':scope > .ell-items');
|
||||
const status = root?.querySelector('[data-ell-more-status]');
|
||||
if (!items || !status || url.origin !== location.origin) return;
|
||||
event.preventDefault();
|
||||
if (link.dataset.ellLoading) return;
|
||||
link.dataset.ellLoading = '1';
|
||||
root.setAttribute('aria-busy', 'true');
|
||||
try {
|
||||
const response = await fetch(url.href, {credentials: 'same-origin'});
|
||||
if (!response.ok || new URL(response.url).origin !== location.origin) throw new Error();
|
||||
const page = new DOMParser().parseFromString(await response.text(), 'text/html');
|
||||
const loop = page.getElementById(root.id);
|
||||
const nextItems = loop?.querySelector(':scope > .ell-items');
|
||||
if (!nextItems?.querySelector('.ell-item')) throw new Error();
|
||||
const lastMonth = Array.from(items.querySelectorAll(':scope > .ell-month')).at(-1);
|
||||
const firstMonth = nextItems.querySelector(':scope > .ell-month');
|
||||
if (firstMonth && lastMonth?.dataset.ellMonth === firstMonth.dataset.ellMonth) firstMonth.remove();
|
||||
const cards = Array.from(nextItems.querySelectorAll(':scope > .ell-item'));
|
||||
items.append(...nextItems.children);
|
||||
root.dispatchEvent(new Event('ell:cards-added'));
|
||||
const nextPage = loop.querySelector('a[rel="next"]');
|
||||
const pageNumber = loop.querySelector('.ell-page');
|
||||
if (pageNumber) root.querySelector('.ell-page').textContent = pageNumber.textContent;
|
||||
status.textContent = nextPage ? status.dataset.loaded : status.dataset.done;
|
||||
if (nextPage) {
|
||||
link.href = nextPage.getAttribute('href');
|
||||
} else {
|
||||
if (document.activeElement === link) status.focus();
|
||||
link.remove();
|
||||
}
|
||||
reinitializeCards(cards);
|
||||
} catch {
|
||||
link.dataset.ellFallback = '1';
|
||||
status.textContent = status.dataset.error;
|
||||
status.focus();
|
||||
} finally {
|
||||
delete link.dataset.ellLoading;
|
||||
root.removeAttribute('aria-busy');
|
||||
}
|
||||
}
|
||||
|
||||
async function copyLink(event) {
|
||||
const button = event.target.closest('[data-ell-copy]');
|
||||
if (!button) return;
|
||||
const input = button.parentElement.querySelector('input');
|
||||
const status = button.parentElement.querySelector('[role="status"]');
|
||||
input.focus();
|
||||
input.select();
|
||||
try {
|
||||
if (navigator.clipboard) {
|
||||
await navigator.clipboard.writeText(input.value);
|
||||
} else if (!document.execCommand('copy')) {
|
||||
return;
|
||||
}
|
||||
status.textContent = button.dataset.copied;
|
||||
button.focus();
|
||||
} catch {
|
||||
// The selected URL remains available for manual copying.
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('click', loadMore);
|
||||
document.addEventListener('click', copyLink);
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => initializeWithin(document), {once: true});
|
||||
} else {
|
||||
initializeWithin(document);
|
||||
}
|
||||
|
||||
let registered = false;
|
||||
function registerElementorPreview() {
|
||||
if (!registered && window.elementorFrontend?.hooks) {
|
||||
registered = true;
|
||||
window.elementorFrontend.hooks.addAction('frontend/element_ready/eventlabs-event-loop.default', (scope) => {
|
||||
if (scope[0]) initializeWithin(scope[0]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
registerElementorPreview();
|
||||
if (!registered && window.jQuery) window.jQuery(window).one('elementor/frontend/init', registerElementorPreview);
|
||||
})();
|
||||
682
addons/eventlabs-loop-builder/assets/presets.css
Normal file
682
addons/eventlabs-loop-builder/assets/presets.css
Normal file
@@ -0,0 +1,682 @@
|
||||
.ell-preset-preview,
|
||||
.ell-item:has(> .ell-preset, > .elementor > .ell-preset),
|
||||
body.single-eventlabs_loop_item .elementor:has(> .ell-preset) {
|
||||
container: ell-card / inline-size;
|
||||
}
|
||||
|
||||
.ell-preset {
|
||||
--elp-ink: #182936;
|
||||
--elp-muted: #4d606c;
|
||||
--elp-accent: #24556b;
|
||||
--elp-tint: #eaf2f6;
|
||||
--elp-line: #d7e1e6;
|
||||
--elp-surface: #fff;
|
||||
--elp-radius: 1rem;
|
||||
--elp-space: 1.2rem;
|
||||
--elp-title-font: Inter, system-ui, sans-serif;
|
||||
--elp-title-size: clamp(1.18rem, 7cqi, 1.8rem);
|
||||
--elp-media-ratio: 16 / 10;
|
||||
--elp-shadow: none;
|
||||
--display: flex;
|
||||
--flex-direction: column;
|
||||
--flex-grow: 1;
|
||||
display: var(--display);
|
||||
flex: 1 1 auto;
|
||||
flex-direction: var(--flex-direction);
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
block-size: 100%;
|
||||
min-inline-size: 0;
|
||||
border: 1px solid var(--elp-line);
|
||||
border-radius: var(--elp-radius);
|
||||
background: var(--elp-surface);
|
||||
box-shadow: var(--elp-shadow);
|
||||
color: var(--elp-ink);
|
||||
text-align: start;
|
||||
font: 450 .92rem/1.5 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-preset.e-con,
|
||||
.ell-preset .e-con:where(.ell-preset-media, .ell-preset-body, .ell-preset-rail, .ell-preset-strip, .ell-preset-hero, .ell-preset-badge, .ell-preset-actions) {
|
||||
--padding-top: var(--elp-block-padding, 0px);
|
||||
--padding-bottom: var(--elp-block-padding, 0px);
|
||||
--padding-left: var(--elp-inline-padding, 0px);
|
||||
--padding-right: var(--elp-inline-padding, 0px);
|
||||
--column-gap: var(--elp-part-gap, 0px);
|
||||
--row-gap: var(--elp-part-gap, 0px);
|
||||
}
|
||||
|
||||
.ell-preset.e-con {
|
||||
--border-radius: var(--elp-radius);
|
||||
}
|
||||
|
||||
body.single-eventlabs_loop_item .ell-preset {
|
||||
max-inline-size: 35rem;
|
||||
margin-inline: auto;
|
||||
}
|
||||
|
||||
body.single-eventlabs_loop_item .ell-preset-layout-list {
|
||||
max-inline-size: 53rem;
|
||||
}
|
||||
|
||||
.ell-preset .ell-preset-body {
|
||||
--display: flex;
|
||||
--flex-direction: column;
|
||||
--flex-grow: 1;
|
||||
--elp-inline-padding: var(--elp-space);
|
||||
--elp-block-padding: var(--elp-space);
|
||||
--elp-part-gap: .55rem;
|
||||
display: var(--display);
|
||||
flex: 1 1 auto;
|
||||
flex-direction: var(--flex-direction);
|
||||
gap: var(--elp-part-gap);
|
||||
min-inline-size: 0;
|
||||
padding-block: var(--padding-top, var(--elp-block-padding)) var(--padding-bottom, var(--elp-block-padding));
|
||||
padding-inline: var(--padding-inline-start, var(--elp-inline-padding)) var(--padding-inline-end, var(--elp-inline-padding));
|
||||
}
|
||||
|
||||
.ell-preset :is(.ell-preset-rail, .ell-preset-strip, .ell-preset-media, .ell-preset-hero) {
|
||||
min-inline-size: 0;
|
||||
}
|
||||
|
||||
.ell-preset .ell-preset-media {
|
||||
--flex-grow: 0;
|
||||
--flex-shrink: 0;
|
||||
--elp-block-padding: 0px;
|
||||
--elp-inline-padding: 0px;
|
||||
display: grid;
|
||||
place-items: stretch;
|
||||
flex: none;
|
||||
aspect-ratio: var(--elp-media-ratio);
|
||||
overflow: hidden;
|
||||
border-start-start-radius: calc(var(--elp-radius) - 1px);
|
||||
border-start-end-radius: calc(var(--elp-radius) - 1px);
|
||||
background: var(--elp-tint);
|
||||
}
|
||||
|
||||
.ell-preset .ell-preset-media :is(.elementor-widget, .elementor-widget-container, .ell-image) {
|
||||
inline-size: 100%;
|
||||
block-size: 100%;
|
||||
}
|
||||
|
||||
.ell-preset .ell-preset-media img {
|
||||
display: block;
|
||||
inline-size: 100%;
|
||||
block-size: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.ell-preset .ell-image > a {
|
||||
display: block;
|
||||
block-size: 100%;
|
||||
}
|
||||
|
||||
.ell-preset .ell-image-placeholder {
|
||||
padding: .5rem;
|
||||
min-block-size: 0;
|
||||
background: linear-gradient(150deg, var(--elp-accent), #172f4a);
|
||||
color: #fff;
|
||||
font: 670 clamp(.95rem, 8cqi, 2.25rem)/1 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-preset-sample-photo {
|
||||
display: block;
|
||||
inline-size: 100%;
|
||||
block-size: 100%;
|
||||
min-block-size: 4.2rem;
|
||||
background:
|
||||
radial-gradient(ellipse at 18% 77%, #33564b 0%, transparent 47%),
|
||||
radial-gradient(ellipse at 29% 66%, #e8b795 0%, transparent 29%),
|
||||
radial-gradient(ellipse at 67% 46%, #e9d1a3 0%, transparent 39%),
|
||||
linear-gradient(143deg, #735c59 3%, #c87e69 36%, #5d7163 67%, #25443d 100%);
|
||||
}
|
||||
|
||||
.ell-preset .ell-field {
|
||||
margin: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.ell-preset .ell-title {
|
||||
color: var(--elp-ink);
|
||||
font: 710 var(--elp-title-size)/1.16 var(--elp-title-font);
|
||||
letter-spacing: -.025em;
|
||||
}
|
||||
|
||||
.ell-preset .ell-title a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.ell-preset .ell-title a:hover {
|
||||
text-decoration: underline;
|
||||
text-underline-offset: .12em;
|
||||
}
|
||||
|
||||
.ell-preset :is(.ell-schedule, .ell-time) {
|
||||
display: block;
|
||||
color: var(--elp-accent);
|
||||
font-size: .83rem;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.ell-preset :is(.ell-venue, .ell-address, .ell-organizer, .ell-excerpt) {
|
||||
color: var(--elp-muted);
|
||||
font-size: .875rem;
|
||||
}
|
||||
|
||||
.ell-preset .ell-venue,
|
||||
.ell-preset .ell-cost {
|
||||
font-weight: 680;
|
||||
}
|
||||
|
||||
.ell-preset .ell-chip,
|
||||
.ell-preset .ell-status {
|
||||
background: var(--elp-tint);
|
||||
color: var(--elp-accent);
|
||||
border-radius: .35rem;
|
||||
font: 650 .72rem/1.35 Inter, system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.ell-preset .ell-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
align-self: flex-start;
|
||||
inline-size: fit-content;
|
||||
min-block-size: 1.8rem;
|
||||
color: var(--elp-accent);
|
||||
font-size: .825rem;
|
||||
font-weight: 720;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: .2em;
|
||||
}
|
||||
|
||||
.ell-preset .ell-preset-body > .ell-link:last-child,
|
||||
.ell-preset .ell-preset-body > .elementor-widget:last-child:has(.ell-link),
|
||||
.ell-preset .ell-preset-body > .ell-preset-actions:last-child {
|
||||
margin-block-start: auto;
|
||||
}
|
||||
|
||||
.ell-preset .ell-preset-actions,
|
||||
.ell-preset .ell-preset-strip {
|
||||
--display: flex;
|
||||
--flex-direction: row;
|
||||
--flex-wrap: wrap;
|
||||
--align-items: center;
|
||||
--justify-content: flex-start;
|
||||
--elp-part-gap: .55rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: .55rem .8rem;
|
||||
}
|
||||
|
||||
.ell-preset .ell-preset-actions {
|
||||
--elp-block-padding: 0px;
|
||||
--elp-inline-padding: 0px;
|
||||
}
|
||||
|
||||
.ell-preset :is(.ell-preset-actions, .ell-preset-strip) > .elementor-widget {
|
||||
--container-widget-width: auto;
|
||||
flex: 0 1 auto;
|
||||
inline-size: auto;
|
||||
max-inline-size: 100%;
|
||||
}
|
||||
|
||||
.ell-preset .ell-preset-rail {
|
||||
--align-items: center;
|
||||
--justify-content: center;
|
||||
--elp-block-padding: .8rem;
|
||||
--elp-inline-padding: .5rem;
|
||||
--elp-part-gap: .45rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: .45rem;
|
||||
padding: .8rem .5rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ell-preset .ell-date-badge {
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: .1em;
|
||||
inline-size: fit-content;
|
||||
margin: 0;
|
||||
padding: .54rem .66rem;
|
||||
border-radius: .62rem;
|
||||
background: var(--elp-tint);
|
||||
color: var(--elp-accent);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ell-preset :is(.ell-date-month, .ell-date-weekday) {
|
||||
font-size: .66rem;
|
||||
font-weight: 710;
|
||||
letter-spacing: .04em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.ell-preset .ell-date-day {
|
||||
font-size: clamp(1.35rem, 7cqi, 2.1rem);
|
||||
font-weight: 730;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.ell-preset :is(a, button, summary):focus-visible {
|
||||
outline: 2px solid currentColor;
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
.ell-item .ell-preset :is(.ell-preset-actions, .ell-preset-strip, .ell-preset-badge):not(:has(.ell-field)) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ell-preset-family-classic {
|
||||
--elp-ink: #2a251d;
|
||||
--elp-muted: #655950;
|
||||
--elp-accent: #744a2d;
|
||||
--elp-tint: #f4ece1;
|
||||
--elp-line: #ded4c8;
|
||||
--elp-surface: #fffcf8;
|
||||
--elp-title-font: Baskervville, Georgia, serif;
|
||||
--elp-radius: .48rem;
|
||||
}
|
||||
|
||||
.ell-preset-family-classic .ell-title {
|
||||
font-weight: 700;
|
||||
letter-spacing: -.013em;
|
||||
}
|
||||
|
||||
.ell-preset-style-program .ell-link,
|
||||
.ell-preset-style-invitation .ell-link,
|
||||
.ell-preset-family-modern .ell-link {
|
||||
padding: .45rem .73rem;
|
||||
border-radius: .36rem;
|
||||
background: var(--elp-accent);
|
||||
color: var(--elp-surface);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.ell-preset-style-program .ell-link:hover,
|
||||
.ell-preset-style-invitation .ell-link:hover,
|
||||
.ell-preset-family-modern .ell-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.ell-preset-style-gazette {
|
||||
--elp-radius: 0rem;
|
||||
--elp-media-ratio: 2 / 1;
|
||||
border-block-start-width: 3px;
|
||||
border-block-start-color: var(--elp-accent);
|
||||
}
|
||||
|
||||
.ell-preset-style-gazette .ell-preset-media {
|
||||
--width: auto;
|
||||
margin-inline: var(--elp-space);
|
||||
margin-block-end: var(--elp-space);
|
||||
inline-size: auto;
|
||||
border-radius: .12rem;
|
||||
}
|
||||
|
||||
.ell-preset-style-gazette .ell-chip {
|
||||
padding-inline: 0;
|
||||
background: transparent;
|
||||
letter-spacing: .08em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.ell-preset-style-invitation {
|
||||
--elp-surface: #f7efdf;
|
||||
--elp-ink: #3a2a22;
|
||||
--elp-title-size: clamp(1.35rem, 9cqi, 2.25rem);
|
||||
--elp-space: 1.5rem;
|
||||
}
|
||||
|
||||
.ell-preset-style-invitation .ell-preset-body {
|
||||
--align-items: center;
|
||||
--justify-content: center;
|
||||
--text-align: center;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ell-preset-style-invitation .ell-preset-body > .elementor-widget {
|
||||
--container-widget-width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ell-preset-style-invitation .ell-categories {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.ell-preset-style-invitation .ell-date-badge {
|
||||
border: 1px solid #a17b5a;
|
||||
border-radius: 50%;
|
||||
min-inline-size: 4.3rem;
|
||||
min-block-size: 4.3rem;
|
||||
justify-content: center;
|
||||
background: #fffaf0;
|
||||
}
|
||||
|
||||
.ell-preset-style-invitation .ell-link {
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.ell-preset-style-ticket,
|
||||
.ell-preset-style-lineup,
|
||||
.ell-preset-style-snapshot {
|
||||
--display: grid;
|
||||
grid-template-columns: minmax(3.2rem, 26%) minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.ell-preset-style-ticket .ell-preset-rail {
|
||||
--elp-tint: transparent;
|
||||
border-inline-end: 1px dashed #b9a38c;
|
||||
border-start-start-radius: calc(var(--elp-radius) - 1px);
|
||||
border-end-start-radius: calc(var(--elp-radius) - 1px);
|
||||
background: #f3e9da;
|
||||
}
|
||||
|
||||
.ell-preset-style-ticket .ell-preset-body,
|
||||
.ell-preset-style-lineup .ell-preset-body,
|
||||
.ell-preset-style-snapshot .ell-preset-body {
|
||||
--elp-inline-padding: .82rem;
|
||||
--elp-block-padding: .92rem;
|
||||
}
|
||||
|
||||
.ell-preset-family-minimal {
|
||||
--elp-radius: .45rem;
|
||||
--elp-line: #dce5e9;
|
||||
--elp-tint: #eef4f5;
|
||||
--elp-accent: #175665;
|
||||
--elp-title-size: clamp(1.08rem, 6cqi, 1.55rem);
|
||||
}
|
||||
|
||||
.ell-preset-style-lineup {
|
||||
border-width: 0 0 1px;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.ell-preset-style-lineup .ell-date-badge {
|
||||
background: transparent;
|
||||
border-block-end: 2px solid var(--elp-line);
|
||||
border-radius: 0;
|
||||
padding-inline: .14rem;
|
||||
}
|
||||
|
||||
.ell-preset-style-bulletin {
|
||||
border-radius: 0;
|
||||
border-width: 1px 0;
|
||||
}
|
||||
|
||||
.ell-preset-style-bulletin .ell-chip {
|
||||
padding-inline: 0;
|
||||
background: transparent;
|
||||
color: var(--elp-muted);
|
||||
letter-spacing: .05em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.ell-preset-style-snapshot {
|
||||
--elp-media-ratio: 1;
|
||||
align-items: center;
|
||||
gap: .4rem;
|
||||
padding-inline-start: .55rem;
|
||||
}
|
||||
|
||||
.ell-preset-style-snapshot .ell-preset-media {
|
||||
border-radius: .38rem;
|
||||
}
|
||||
|
||||
.ell-preset-style-snapshot .ell-image-placeholder {
|
||||
padding: .2rem;
|
||||
font-size: clamp(.75rem, 6cqi, 1.45rem);
|
||||
}
|
||||
|
||||
.ell-preset-style-agenda .ell-preset-strip {
|
||||
--elp-block-padding: .55rem;
|
||||
--elp-inline-padding: var(--elp-space);
|
||||
padding: var(--elp-block-padding) var(--elp-inline-padding);
|
||||
border-block-end: 1px solid var(--elp-line);
|
||||
border-start-start-radius: calc(var(--elp-radius) - 1px);
|
||||
border-start-end-radius: calc(var(--elp-radius) - 1px);
|
||||
background: var(--elp-tint);
|
||||
}
|
||||
|
||||
.ell-preset-family-modern {
|
||||
--elp-ink: #182437;
|
||||
--elp-muted: #4c5d74;
|
||||
--elp-accent: #3c46a4;
|
||||
--elp-tint: #edf0fc;
|
||||
--elp-line: #dce2f2;
|
||||
--elp-shadow: 0 .4rem 1.25rem rgba(23, 42, 79, .085);
|
||||
--elp-radius: 1.15rem;
|
||||
}
|
||||
|
||||
.ell-preset-family-modern .ell-link {
|
||||
border-radius: 2rem;
|
||||
}
|
||||
|
||||
.ell-preset-style-cover {
|
||||
--display: grid;
|
||||
--elp-ink: #fff;
|
||||
--elp-muted: #f1f2f8;
|
||||
--elp-accent: #fff;
|
||||
--elp-tint: #15273e;
|
||||
--elp-line: #15273e;
|
||||
--elp-surface: #15273e;
|
||||
--elp-title-size: clamp(1.35rem, 8cqi, 2.15rem);
|
||||
isolation: isolate;
|
||||
min-block-size: 15.75rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ell-preset-style-cover > :is(.ell-preset-media, .ell-preset-body) {
|
||||
grid-area: 1 / 1;
|
||||
}
|
||||
|
||||
.ell-preset-style-cover > .ell-preset-media {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
aspect-ratio: auto;
|
||||
inline-size: 100%;
|
||||
block-size: 100%;
|
||||
border-radius: inherit;
|
||||
}
|
||||
|
||||
.ell-preset-style-cover .ell-preset-media::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: linear-gradient(0deg, rgba(12, 18, 37, .98), rgba(12, 18, 37, .82) 48%, rgba(12, 18, 37, .14) 100%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.ell-preset-style-cover > .ell-preset-body {
|
||||
z-index: 1;
|
||||
align-self: end;
|
||||
}
|
||||
|
||||
.ell-preset-style-cover .ell-image-placeholder,
|
||||
.ell-preset-style-split .ell-image-placeholder {
|
||||
background: linear-gradient(139deg, #514c9f, #263d75 56%, #1f2449);
|
||||
}
|
||||
|
||||
.ell-preset-style-cover .ell-image-placeholder {
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
.ell-preset-style-cover .ell-chip {
|
||||
background: #1e3152;
|
||||
}
|
||||
|
||||
.ell-preset-style-split {
|
||||
--elp-ink: #fff;
|
||||
--elp-muted: #e7edf8;
|
||||
--elp-accent: #dce7ff;
|
||||
--elp-tint: #243d65;
|
||||
--elp-surface: #162640;
|
||||
--elp-line: #223752;
|
||||
}
|
||||
|
||||
.ell-preset-style-split .ell-preset-media {
|
||||
--elp-media-ratio: 2 / 1;
|
||||
}
|
||||
|
||||
.ell-preset-style-split .ell-share {
|
||||
color: var(--elp-ink);
|
||||
}
|
||||
|
||||
.ell-preset-style-panorama .ell-preset-hero {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.ell-preset-style-panorama .ell-preset-badge {
|
||||
--width: auto;
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
inset-block-start: .6rem;
|
||||
inset-inline-end: .6rem;
|
||||
}
|
||||
|
||||
.ell-preset-style-panorama .ell-date-badge {
|
||||
background: #fff;
|
||||
color: #273d65;
|
||||
box-shadow: 0 .2rem .8rem rgba(16, 36, 73, .25);
|
||||
}
|
||||
|
||||
.ell-preset-style-studio {
|
||||
--elp-surface: #f2f4ff;
|
||||
--elp-line: #d9e1f8;
|
||||
}
|
||||
|
||||
.ell-preset-style-studio .ell-preset-strip {
|
||||
--elp-inline-padding: var(--elp-space);
|
||||
--elp-block-padding: .63rem;
|
||||
min-block-size: 1.7rem;
|
||||
padding: var(--elp-block-padding) var(--elp-inline-padding);
|
||||
border-start-start-radius: calc(var(--elp-radius) - 1px);
|
||||
border-start-end-radius: calc(var(--elp-radius) - 1px);
|
||||
background: #2a397c;
|
||||
}
|
||||
|
||||
.ell-preset-style-studio .ell-preset-strip :is(.ell-chip, .ell-status) {
|
||||
background: #e1e8ff;
|
||||
color: #27356d;
|
||||
}
|
||||
|
||||
.ell-preset-layout-list {
|
||||
--elp-title-size: clamp(1.13rem, 5cqi, 1.75rem);
|
||||
--elp-space: .95rem;
|
||||
}
|
||||
|
||||
.ell-preset-layout-list:is(.ell-preset-style-program, .ell-preset-style-gazette, .ell-preset-style-split, .ell-preset-style-panorama) {
|
||||
--display: grid;
|
||||
grid-template-columns: minmax(4.2rem, 28%) minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-gazette {
|
||||
grid-template-columns: minmax(0, 1fr) minmax(4.2rem, 28%);
|
||||
}
|
||||
|
||||
.ell-preset-layout-list :is(.ell-preset-media, .ell-preset-hero) {
|
||||
align-self: stretch;
|
||||
aspect-ratio: auto;
|
||||
}
|
||||
|
||||
.ell-preset-layout-list :is(.ell-preset-media, .ell-preset-hero) :is(img, .ell-image-placeholder, .ell-preset-sample-photo) {
|
||||
block-size: 100%;
|
||||
}
|
||||
|
||||
.ell-preset-layout-list :is(.ell-preset-media, .ell-preset-hero) > :is(.ell-preset-media, .ell-image, .elementor-widget) {
|
||||
block-size: 100%;
|
||||
}
|
||||
|
||||
.ell-preset-layout-list:not(.ell-preset-style-gazette, .ell-preset-style-cover, .ell-preset-style-snapshot) .ell-preset-media {
|
||||
border-start-end-radius: 0;
|
||||
border-end-start-radius: calc(var(--elp-radius) - 1px);
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-gazette .ell-preset-media {
|
||||
margin-inline: 0 var(--elp-space);
|
||||
margin-block: var(--elp-space);
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-snapshot .ell-preset-media {
|
||||
align-self: center;
|
||||
aspect-ratio: 1;
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-cover {
|
||||
min-block-size: 11.5rem;
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-cover .ell-preset-body {
|
||||
max-inline-size: 42rem;
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-cover .ell-preset-media::after {
|
||||
background: linear-gradient(90deg, rgba(12, 18, 37, .97), rgba(12, 18, 37, .76) 70%, rgba(12, 18, 37, .28));
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-cover:dir(rtl) .ell-preset-media::after {
|
||||
background: linear-gradient(270deg, rgba(12, 18, 37, .97), rgba(12, 18, 37, .76) 70%, rgba(12, 18, 37, .28));
|
||||
}
|
||||
|
||||
.ell-preset-layout-carousel {
|
||||
--elp-media-ratio: 3 / 2;
|
||||
--elp-space: 1.05rem;
|
||||
}
|
||||
|
||||
.ell-preset-layout-carousel.ell-preset-style-cover {
|
||||
min-block-size: 17.75rem;
|
||||
}
|
||||
|
||||
.ell-preset-layout-carousel.ell-preset-style-snapshot {
|
||||
--elp-media-ratio: 1;
|
||||
}
|
||||
|
||||
@container ell-card (min-width: 35rem) {
|
||||
.ell-preset-layout-list.ell-preset-style-ticket,
|
||||
.ell-preset-layout-list.ell-preset-style-lineup {
|
||||
grid-template-columns: 6.5rem minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-snapshot {
|
||||
grid-template-columns: 8rem minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-agenda {
|
||||
--display: grid;
|
||||
grid-template-columns: 29% minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-agenda .ell-preset-strip {
|
||||
border-block-end: 0;
|
||||
border-inline-end: 1px solid var(--elp-line);
|
||||
border-start-end-radius: 0;
|
||||
border-end-start-radius: calc(var(--elp-radius) - 1px);
|
||||
}
|
||||
}
|
||||
|
||||
@container ell-card (max-width: 17.99rem) {
|
||||
.ell-preset {
|
||||
--elp-space: .85rem;
|
||||
}
|
||||
|
||||
.ell-preset-style-ticket .ell-date-badge {
|
||||
padding-inline: 0;
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-panorama .ell-preset-badge {
|
||||
inset-block-start: .35rem;
|
||||
inset-inline-end: .35rem;
|
||||
}
|
||||
|
||||
.ell-preset-layout-list.ell-preset-style-panorama .ell-date-badge {
|
||||
padding: .35rem;
|
||||
}
|
||||
}
|
||||
76
addons/eventlabs-loop-builder/eventlabs-loop-builder.php
Normal file
76
addons/eventlabs-loop-builder/eventlabs-loop-builder.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: eventLabs Loop Builder
|
||||
* Description: Design reusable Elementor event cards and display eventLabs events in grids, lists, and carousels.
|
||||
* Version: 0.2.0
|
||||
* Requires at least: 6.9
|
||||
* Requires PHP: 8.1
|
||||
* Requires Plugins: burn-events, elementor
|
||||
* Author: hostLabs
|
||||
* Update URI: https://git.labs.casa/josh/eventLabs/src/branch/main/addons/eventlabs-loop-builder
|
||||
* Text Domain: eventlabs-loop-builder
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace EventLabs\LoopBuilder;
|
||||
|
||||
use BurnEvents\Events;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
const VERSION = '0.2.0';
|
||||
const FILE = __FILE__;
|
||||
const ASSET = 'eventlabs-loop-builder';
|
||||
const CORE_MINIMUM = '0.5.8';
|
||||
const ELEMENTOR_MINIMUM = '3.27.0';
|
||||
|
||||
add_action( 'plugins_loaded', static function (): void {
|
||||
$core_ready = defined( 'BURN_EVENTS_VERSION' ) && version_compare( BURN_EVENTS_VERSION, CORE_MINIMUM, '>=' ) && class_exists( Events::class );
|
||||
$elementor_ready = defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, ELEMENTOR_MINIMUM, '>=' ) && did_action( 'elementor/loaded' );
|
||||
if ( ! $core_ready || ! $elementor_ready ) {
|
||||
add_action( 'admin_notices', static function (): void {
|
||||
if ( current_user_can( 'activate_plugins' ) ) {
|
||||
printf(
|
||||
'<div class="notice notice-warning"><p>%s</p></div>',
|
||||
esc_html( sprintf(
|
||||
/* translators: 1: minimum eventLabs version; 2: minimum Elementor version */
|
||||
__( 'eventLabs Loop Builder requires eventLabs %1$s or later and Elementor %2$s or later. Activate or update both plugins to use the builder.', 'eventlabs-loop-builder' ),
|
||||
CORE_MINIMUM,
|
||||
ELEMENTOR_MINIMUM
|
||||
) )
|
||||
);
|
||||
}
|
||||
} );
|
||||
return;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/includes/class-card.php';
|
||||
require_once __DIR__ . '/includes/class-presets.php';
|
||||
require_once __DIR__ . '/includes/class-query.php';
|
||||
require_once __DIR__ . '/includes/class-templates.php';
|
||||
require_once __DIR__ . '/includes/class-library.php';
|
||||
|
||||
Templates::register();
|
||||
Library::register();
|
||||
|
||||
add_action( 'init', static function (): void {
|
||||
wp_register_style( ASSET, plugins_url( 'assets/loop.css', FILE ), [], VERSION );
|
||||
wp_register_style( ASSET . '-presets', plugins_url( 'assets/presets.css', FILE ), [ ASSET ], VERSION );
|
||||
wp_register_script( ASSET, plugins_url( 'assets/loop.js', FILE ), [ 'elementor-frontend' ], VERSION, [ 'in_footer' => true, 'strategy' => 'defer' ] );
|
||||
} );
|
||||
|
||||
add_action( 'elementor/widgets/register', static function ( \Elementor\Widgets_Manager $widgets ): void {
|
||||
require_once __DIR__ . '/includes/class-widgets.php';
|
||||
$widgets->register( new Loop_Widget() );
|
||||
$widgets->register( new Field_Widget() );
|
||||
} );
|
||||
|
||||
add_action( 'elementor/dynamic_tags/register', static function ( \Elementor\Core\DynamicTags\Manager $tags ): void {
|
||||
require_once __DIR__ . '/includes/class-tags.php';
|
||||
$tags->register_group( ASSET, [ 'title' => __( 'eventLabs Event Loop', 'eventlabs-loop-builder' ) ] );
|
||||
$tags->register( new Field_Tag() );
|
||||
$tags->register( new Link_Tag() );
|
||||
$tags->register( new Image_Tag() );
|
||||
} );
|
||||
}, 20 );
|
||||
215
addons/eventlabs-loop-builder/includes/class-card.php
Normal file
215
addons/eventlabs-loop-builder/includes/class-card.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace EventLabs\LoopBuilder;
|
||||
|
||||
use BurnEvents\Admin;
|
||||
use BurnEvents\Calendar;
|
||||
use BurnEvents\Events;
|
||||
use BurnEvents\Map_View;
|
||||
use BurnEvents\Maps;
|
||||
use DateTimeImmutable;
|
||||
use WP_Post;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
final class Card {
|
||||
private array $data;
|
||||
|
||||
public function __construct( private readonly WP_Post $event, private readonly ?array $occurrence ) {
|
||||
$this->data = Events::event_data( $event->ID );
|
||||
}
|
||||
|
||||
public static function fields(): array {
|
||||
return [
|
||||
'title' => __( 'Event title', 'eventlabs-loop-builder' ),
|
||||
'image' => __( 'Featured image', 'eventlabs-loop-builder' ),
|
||||
'schedule' => __( 'Date and time', 'eventlabs-loop-builder' ),
|
||||
'date' => __( 'Start date', 'eventlabs-loop-builder' ),
|
||||
'date_badge' => __( 'Date badge', 'eventlabs-loop-builder' ),
|
||||
'time' => __( 'Start time', 'eventlabs-loop-builder' ),
|
||||
'venue' => __( 'Venue', 'eventlabs-loop-builder' ),
|
||||
'address' => __( 'Venue address', 'eventlabs-loop-builder' ),
|
||||
'map' => __( 'Venue map', 'eventlabs-loop-builder' ),
|
||||
'organizer' => __( 'Organizers', 'eventlabs-loop-builder' ),
|
||||
'series' => __( 'Series', 'eventlabs-loop-builder' ),
|
||||
'excerpt' => __( 'Excerpt', 'eventlabs-loop-builder' ),
|
||||
'categories' => __( 'Categories', 'eventlabs-loop-builder' ),
|
||||
'tags' => __( 'Tags', 'eventlabs-loop-builder' ),
|
||||
'cost' => __( 'Cost', 'eventlabs-loop-builder' ),
|
||||
'status' => __( 'Status or featured label', 'eventlabs-loop-builder' ),
|
||||
'link' => __( 'Event link', 'eventlabs-loop-builder' ),
|
||||
'website' => __( 'Event website', 'eventlabs-loop-builder' ),
|
||||
'share' => __( 'Share event', 'eventlabs-loop-builder' ),
|
||||
'custom' => __( 'Custom event field', 'eventlabs-loop-builder' ),
|
||||
];
|
||||
}
|
||||
|
||||
public static function text_fields(): array {
|
||||
return array_diff_key( self::fields(), array_flip( [ 'image', 'link', 'website', 'date_badge', 'share', 'map' ] ) );
|
||||
}
|
||||
|
||||
public static function custom_fields(): array {
|
||||
return array_map( static fn( array $field ): string => $field['label'], Admin::options()['fields'] );
|
||||
}
|
||||
|
||||
public function link(): string {
|
||||
return (string) ( $this->occurrence ? Events::event_url( $this->occurrence ) : get_permalink( $this->event ) );
|
||||
}
|
||||
|
||||
public function image(): array {
|
||||
$id = (int) get_post_thumbnail_id( $this->event );
|
||||
return [ 'id' => $id, 'url' => $id ? (string) wp_get_attachment_image_url( $id, 'large' ) : '' ];
|
||||
}
|
||||
|
||||
public function month(): ?DateTimeImmutable {
|
||||
return $this->occurrence ? Events::local_time( $this->occurrence['starts_at'], wp_timezone_string() ) : null;
|
||||
}
|
||||
|
||||
private function start(): ?DateTimeImmutable {
|
||||
return $this->occurrence ? Events::local_time( $this->occurrence['starts_at'], $this->data['schedule']['timezone'] ?? wp_timezone_string() ) : null;
|
||||
}
|
||||
|
||||
private function formatted_start( string $format ): string {
|
||||
$start = $this->start();
|
||||
return $start ? wp_date( $format, $start->getTimestamp(), $start->getTimezone() ) : '';
|
||||
}
|
||||
|
||||
private function relations( string $relation ): string {
|
||||
$posts = Events::locations( $this->data[ $relation ], Events::RELATIONS[ $relation ] );
|
||||
return implode( ', ', array_map( 'get_the_title', $posts ) );
|
||||
}
|
||||
|
||||
private function terms( string $taxonomy ): array {
|
||||
$terms = get_the_terms( $this->event, $taxonomy );
|
||||
return is_array( $terms ) ? wp_list_pluck( $terms, 'name' ) : [];
|
||||
}
|
||||
|
||||
private function custom_value( string $field ): string {
|
||||
$settings = Admin::options()['fields'][ $field ] ?? null;
|
||||
$value = $this->data['fields'][ $field ] ?? '';
|
||||
if ( ! $settings || '' === $value ) {
|
||||
return '';
|
||||
}
|
||||
return 'checkbox' === $settings['type'] ? __( 'Yes', 'eventlabs-loop-builder' ) : (string) $value;
|
||||
}
|
||||
|
||||
private function address(): string {
|
||||
$venue = Events::locations( $this->data['venue'], Events::VENUE )[0] ?? null;
|
||||
return $venue ? Maps::address( Events::location_data( $venue->ID ) ) : $this->data['location'];
|
||||
}
|
||||
|
||||
public function value( string $field, string $custom = '' ): string {
|
||||
return match ( $field ) {
|
||||
'title' => get_the_title( $this->event ),
|
||||
'schedule' => $this->occurrence ? Calendar::period( $this->occurrence, $this->data ) : '',
|
||||
'date' => $this->formatted_start( (string) get_option( 'date_format' ) ),
|
||||
'time' => ! empty( $this->data['schedule']['all_day'] ) ? __( 'All day', 'eventlabs-loop-builder' ) : $this->formatted_start( (string) get_option( 'time_format' ) ),
|
||||
'venue' => Calendar::event_location( $this->data ),
|
||||
'address' => $this->address(),
|
||||
'organizer', 'series' => $this->relations( $field ),
|
||||
'excerpt' => Calendar::event_excerpt( $this->event->ID ),
|
||||
'categories' => implode( ', ', $this->terms( Events::CATEGORY ) ),
|
||||
'tags' => implode( ', ', $this->terms( 'post_tag' ) ),
|
||||
'cost' => '0' === $this->data['cost'] ? __( 'Free', 'eventlabs-loop-builder' ) : $this->data['cost'],
|
||||
'status' => 'scheduled' !== $this->data['status']
|
||||
? ( Events::statuses()[ $this->data['status'] ] ?? '' )
|
||||
: ( $this->data['featured'] ? __( 'Featured', 'eventlabs-loop-builder' ) : '' ),
|
||||
'custom' => $this->custom_value( $custom ),
|
||||
'website' => $this->data['url'],
|
||||
'link' => $this->link(),
|
||||
default => '',
|
||||
};
|
||||
}
|
||||
|
||||
public function field( string $field, array $settings = [] ): string {
|
||||
if ( 'image' === $field ) {
|
||||
$size = (string) ( $settings['image_size'] ?? 'large' );
|
||||
$image = get_the_post_thumbnail( $this->event, $size );
|
||||
if ( ! $image && 'yes' === ( $settings['show_placeholder'] ?? '' ) ) {
|
||||
$date = $this->formatted_start( 'M j' );
|
||||
$image = '<span class="ell-image-placeholder" aria-hidden="true">' . esc_html( $date ) . '</span>';
|
||||
}
|
||||
if ( $image && 'yes' === ( $settings['link_image'] ?? '' ) ) {
|
||||
$image = '<a href="' . esc_url( $this->link() ) . '" aria-label="' . esc_attr( get_the_title( $this->event ) ) . '">' . $image . '</a>';
|
||||
}
|
||||
return $image ? '<figure class="ell-field ell-image">' . $image . '</figure>' : '';
|
||||
}
|
||||
if ( 'date_badge' === $field ) {
|
||||
return $this->date_badge();
|
||||
}
|
||||
if ( 'share' === $field ) {
|
||||
return $this->share();
|
||||
}
|
||||
if ( 'map' === $field ) {
|
||||
$map = Map_View::venues( Events::locations( $this->data['venue'], Events::VENUE ) );
|
||||
return $map ? '<div class="ell-field ell-venue-map">' . $map . '</div>' : '';
|
||||
}
|
||||
$value = $this->value( $field, (string) ( $settings['custom_key'] ?? '' ) );
|
||||
if ( 'excerpt' === $field && ! empty( $settings['excerpt_words'] ) ) {
|
||||
$words = min( 100, max( 1, (int) $settings['excerpt_words'] ) );
|
||||
$raw = $this->event->post_excerpt ?: $this->event->post_content;
|
||||
$value = wp_trim_words( wp_strip_all_tags( strip_shortcodes( $raw ) ), $words );
|
||||
}
|
||||
if ( '' === $value ) {
|
||||
return '';
|
||||
}
|
||||
if ( 'title' === $field ) {
|
||||
$tag = $settings['heading_tag'] ?? 'h3';
|
||||
$tag = in_array( $tag, [ 'h2', 'h3', 'h4', 'h5', 'h6', 'p' ], true ) ? $tag : 'h3';
|
||||
$content = esc_html( $value );
|
||||
if ( 'yes' === ( $settings['link_title'] ?? 'yes' ) ) {
|
||||
$content = '<a href="' . esc_url( $this->link() ) . '">' . $content . '</a>';
|
||||
}
|
||||
return '<' . $tag . ' class="ell-field ell-title">' . $content . '</' . $tag . '>';
|
||||
}
|
||||
if ( in_array( $field, [ 'link', 'website' ], true ) ) {
|
||||
$label = trim( (string) ( $settings['link_label'] ?? '' ) );
|
||||
if ( '' === $label ) {
|
||||
$label = 'link' === $field ? __( 'View event', 'eventlabs-loop-builder' ) : __( 'Event website', 'eventlabs-loop-builder' );
|
||||
}
|
||||
/* translators: 1: link label; 2: event title */
|
||||
$aria = sprintf( __( '%1$s: %2$s', 'eventlabs-loop-builder' ), $label, $this->value( 'title' ) );
|
||||
return '<a class="ell-field ell-link" href="' . esc_url( $value ) . '" aria-label="' . esc_attr( $aria ) . '">' . esc_html( $label ) . '</a>';
|
||||
}
|
||||
if ( in_array( $field, [ 'categories', 'tags' ], true ) ) {
|
||||
$terms = $this->terms( 'categories' === $field ? Events::CATEGORY : 'post_tag' );
|
||||
$chips = array_map( static fn( string $term ): string => '<span class="ell-chip">' . esc_html( $term ) . '</span>', $terms );
|
||||
return '<div class="ell-field ell-' . esc_attr( $field ) . '">' . implode( '', $chips ) . '</div>';
|
||||
}
|
||||
if ( 'schedule' === $field && ( $start = $this->start() ) ) {
|
||||
return '<time class="ell-field ell-schedule" datetime="' . esc_attr( $start->format( DATE_ATOM ) ) . '">' . esc_html( $value ) . '</time>';
|
||||
}
|
||||
return '<p class="ell-field ell-' . esc_attr( $field ) . '">' . esc_html( $value ) . '</p>';
|
||||
}
|
||||
|
||||
private function date_badge(): string {
|
||||
$start = $this->start();
|
||||
if ( ! $start ) {
|
||||
return '';
|
||||
}
|
||||
return '<time class="ell-field ell-date-badge" datetime="' . esc_attr( $start->format( DATE_ATOM ) ) . '" aria-label="' . esc_attr( $this->formatted_start( 'l, F j, Y' ) ) . '">'
|
||||
. '<span class="ell-date-month">' . esc_html( $this->formatted_start( 'M' ) ) . '</span>'
|
||||
. '<strong class="ell-date-day">' . esc_html( $this->formatted_start( 'j' ) ) . '</strong>'
|
||||
. '<span class="ell-date-weekday">' . esc_html( $this->formatted_start( 'D' ) ) . '</span></time>';
|
||||
}
|
||||
|
||||
private function share(): string {
|
||||
$url = $this->link();
|
||||
$subject = wp_specialchars_decode( $this->value( 'title' ), ENT_QUOTES );
|
||||
$email = 'mailto:?subject=' . rawurlencode( $subject ) . '&body=' . rawurlencode( $url );
|
||||
return '<details class="ell-field ell-share"><summary>' . esc_html__( 'Share', 'eventlabs-loop-builder' ) . '</summary><div>'
|
||||
. '<input type="url" readonly value="' . esc_attr( $url ) . '" aria-label="' . esc_attr__( 'Event URL', 'eventlabs-loop-builder' ) . '">'
|
||||
. '<button type="button" data-ell-copy data-copied="' . esc_attr__( 'Link copied', 'eventlabs-loop-builder' ) . '">' . esc_html__( 'Copy link', 'eventlabs-loop-builder' ) . '</button>'
|
||||
. '<a href="' . esc_url( $email ) . '">' . esc_html__( 'Email', 'eventlabs-loop-builder' ) . '</a><span class="ell-share-status" role="status"></span></div></details>';
|
||||
}
|
||||
|
||||
public function built_in(): string {
|
||||
$fields = [ 'categories', 'schedule', 'title', 'venue', 'excerpt' ];
|
||||
$meta = $this->field( 'cost' ) . $this->field( 'status' );
|
||||
return '<div class="ell-starter ell-starter-photo">'
|
||||
. '<div class="ell-starter-media">' . $this->field( 'image', [ 'show_placeholder' => 'yes' ] ) . '</div>'
|
||||
. '<div class="ell-starter-body">' . implode( '', array_map( $this->field( ... ), $fields ) )
|
||||
. ( $meta ? '<div class="ell-starter-meta">' . $meta . '</div>' : '' ) . $this->field( 'link' ) . '</div>'
|
||||
. '</div>';
|
||||
}
|
||||
}
|
||||
110
addons/eventlabs-loop-builder/includes/class-library.php
Normal file
110
addons/eventlabs-loop-builder/includes/class-library.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace EventLabs\LoopBuilder;
|
||||
|
||||
use BurnEvents\Events;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
final class Library {
|
||||
private const PAGE = 'eventlabs-loop-presets';
|
||||
|
||||
public static function register(): void {
|
||||
add_action( 'admin_menu', [ self::class, 'menu' ] );
|
||||
add_action( 'manage_posts_extra_tablenav', [ self::class, 'list_link' ] );
|
||||
}
|
||||
|
||||
private static function url( array $filters = [] ): string {
|
||||
return add_query_arg( [ 'post_type' => Events::EVENT, 'page' => self::PAGE ] + $filters, admin_url( 'edit.php' ) );
|
||||
}
|
||||
|
||||
public static function menu(): void {
|
||||
$label = __( 'Loop Presets', 'eventlabs-loop-builder' );
|
||||
$page = add_submenu_page( 'edit.php?post_type=' . Events::EVENT, $label, $label, Templates::CAPABILITY, self::PAGE, [ self::class, 'render' ] );
|
||||
if ( $page ) {
|
||||
add_action( 'admin_enqueue_scripts', static function ( string $screen ) use ( $page ): void {
|
||||
if ( $page === $screen ) {
|
||||
wp_enqueue_style( ASSET . '-library', plugins_url( 'assets/library.css', FILE ), [ ASSET . '-presets' ], VERSION );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
public static function list_link( string $position ): void {
|
||||
$screen = get_current_screen();
|
||||
if ( 'top' === $position && $screen && Templates::POST_TYPE === $screen->post_type && current_user_can( Templates::CAPABILITY ) ) {
|
||||
echo '<a class="button" href="' . esc_url( self::url() ) . '">' . esc_html__( 'Browse loop presets', 'eventlabs-loop-builder' ) . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
private static function selected( string $key, array $options ): string {
|
||||
$value = isset( $_GET[ $key ] ) && is_string( $_GET[ $key ] ) ? sanitize_key( wp_unslash( $_GET[ $key ] ) ) : '';
|
||||
return isset( $options[ $value ] ) ? $value : '';
|
||||
}
|
||||
|
||||
public static function render(): void {
|
||||
if ( ! current_user_can( Templates::CAPABILITY ) ) {
|
||||
wp_die( esc_html__( 'You cannot view loop presets.', 'eventlabs-loop-builder' ), '', [ 'response' => 403 ] );
|
||||
}
|
||||
$layouts = Presets::layouts();
|
||||
$families = Presets::families();
|
||||
$layout = self::selected( 'ell_layout', $layouts );
|
||||
$family = self::selected( 'ell_family', $families );
|
||||
$presets = array_filter( Presets::catalog(), static fn( array $style ): bool => ( ! $layout || $layout === $style['layout'] ) && ( ! $family || $family === $style['family'] ) );
|
||||
?>
|
||||
<div class="wrap ell-library">
|
||||
<h1><?php esc_html_e( 'Loop Presets', 'eventlabs-loop-builder' ); ?></h1>
|
||||
<p><?php esc_html_e( 'Choose a style to create an editable copy in Elementor. You can also select any preset directly in the Event Loop widget.', 'eventlabs-loop-builder' ); ?></p>
|
||||
<div class="ell-library-toolbar">
|
||||
<form class="ell-library-filters" method="get" action="<?php echo esc_url( admin_url( 'edit.php' ) ); ?>">
|
||||
<input type="hidden" name="post_type" value="<?php echo esc_attr( Events::EVENT ); ?>">
|
||||
<input type="hidden" name="page" value="<?php echo esc_attr( self::PAGE ); ?>">
|
||||
<?php self::select( 'ell_layout', __( 'Layout', 'eventlabs-loop-builder' ), [ '' => __( 'All layouts', 'eventlabs-loop-builder' ) ] + $layouts, $layout ); ?>
|
||||
<?php self::select( 'ell_family', __( 'Style', 'eventlabs-loop-builder' ), [ '' => __( 'All styles', 'eventlabs-loop-builder' ) ] + $families, $family ); ?>
|
||||
<button class="button" type="submit"><?php esc_html_e( 'Filter presets', 'eventlabs-loop-builder' ); ?></button>
|
||||
<?php if ( $layout || $family ) : ?>
|
||||
<a href="<?php echo esc_url( self::url() ); ?>"><?php esc_html_e( 'Clear filters', 'eventlabs-loop-builder' ); ?></a>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
<a class="button" href="<?php echo esc_url( admin_url( 'edit.php?post_type=' . Templates::POST_TYPE ) ); ?>"><?php esc_html_e( 'My loop templates', 'eventlabs-loop-builder' ); ?></a>
|
||||
</div>
|
||||
<p class="ell-library-count"><?php
|
||||
/* translators: %s: number of presets. */
|
||||
printf( esc_html( _n( '%s preset', '%s presets', count( $presets ), 'eventlabs-loop-builder' ) ), esc_html( number_format_i18n( count( $presets ) ) ) );
|
||||
?></p>
|
||||
<div class="ell-library-grid">
|
||||
<?php foreach ( $presets as $slug => $style ) : ?>
|
||||
<article class="ell-library-item">
|
||||
<div class="ell-preset-preview" aria-hidden="true"><?php echo Presets::sample( $slug ); // Preset renderer escapes its content. ?></div>
|
||||
<div class="ell-library-details">
|
||||
<p class="ell-library-type"><?php echo esc_html( $families[ $style['family'] ] . ' · ' . $layouts[ $style['layout'] ] ); ?></p>
|
||||
<h2><?php echo esc_html( $style['title'] ); ?></h2>
|
||||
<p class="ell-library-description"><?php echo esc_html( $style['description'] ); ?></p>
|
||||
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post">
|
||||
<input type="hidden" name="action" value="<?php echo esc_attr( Templates::STARTER_ACTION ); ?>">
|
||||
<input type="hidden" name="preset" value="<?php echo esc_attr( $slug ); ?>">
|
||||
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( Templates::STARTER_ACTION ) ); ?>">
|
||||
<button class="button button-primary" type="submit" aria-label="<?php
|
||||
/* translators: 1: style family, 2: layout, 3: preset name. */
|
||||
printf( esc_attr__( 'Use %1$s %2$s %3$s', 'eventlabs-loop-builder' ), esc_attr( $families[ $style['family'] ] ), esc_attr( $layouts[ $style['layout'] ] ), esc_attr( $style['title'] ) );
|
||||
?>"><?php esc_html_e( 'Use preset', 'eventlabs-loop-builder' ); ?></button>
|
||||
</form>
|
||||
</div>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function select( string $name, string $label, array $options, string $current ): void {
|
||||
?>
|
||||
<label for="<?php echo esc_attr( $name ); ?>"><?php echo esc_html( $label ); ?></label>
|
||||
<select id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?>">
|
||||
<?php foreach ( $options as $value => $title ) : ?>
|
||||
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $current, $value ); ?>><?php echo esc_html( $title ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
259
addons/eventlabs-loop-builder/includes/class-presets.php
Normal file
259
addons/eventlabs-loop-builder/includes/class-presets.php
Normal file
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
|
||||
namespace EventLabs\LoopBuilder;
|
||||
|
||||
use Elementor\Utils;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
final class Presets {
|
||||
public static function families(): array {
|
||||
return [
|
||||
'classic' => __( 'Classic', 'eventlabs-loop-builder' ),
|
||||
'minimal' => __( 'Minimal', 'eventlabs-loop-builder' ),
|
||||
'modern' => __( 'Modern', 'eventlabs-loop-builder' ),
|
||||
];
|
||||
}
|
||||
|
||||
public static function layouts(): array {
|
||||
return [
|
||||
'grid' => __( 'Grid', 'eventlabs-loop-builder' ),
|
||||
'list' => __( 'List', 'eventlabs-loop-builder' ),
|
||||
'carousel' => __( 'Carousel', 'eventlabs-loop-builder' ),
|
||||
];
|
||||
}
|
||||
|
||||
public static function catalog(): array {
|
||||
static $catalog;
|
||||
if ( isset( $catalog ) ) {
|
||||
return $catalog;
|
||||
}
|
||||
$catalog = [];
|
||||
foreach ( self::recipes() as $family => $recipes ) {
|
||||
foreach ( array_keys( self::layouts() ) as $layout ) {
|
||||
foreach ( $recipes as $name => $recipe ) {
|
||||
$catalog[ "$family-$layout-$name" ] = [
|
||||
'title' => $recipe['title'],
|
||||
'description' => $recipe['description'],
|
||||
'family' => $family,
|
||||
'layout' => $layout,
|
||||
'recipe' => $name,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $catalog;
|
||||
}
|
||||
|
||||
public static function elements( string $slug ): array {
|
||||
$tree = self::tree( $slug );
|
||||
return $tree ? [ self::element( $tree, false ) ] : [];
|
||||
}
|
||||
|
||||
public static function render( string $slug, Card $card ): string {
|
||||
$tree = self::tree( $slug );
|
||||
return $tree ? self::markup( $tree, $card ) : '';
|
||||
}
|
||||
|
||||
public static function sample( string $slug ): string {
|
||||
$tree = self::tree( $slug );
|
||||
return $tree ? self::markup( $tree, null ) : '';
|
||||
}
|
||||
|
||||
private static function recipes(): array {
|
||||
static $recipes;
|
||||
if ( isset( $recipes ) ) {
|
||||
return $recipes;
|
||||
}
|
||||
|
||||
$group = static fn( string $name, array $children ): array => [ 'classes' => 'ell-preset-' . $name, 'children' => $children ];
|
||||
$photo = static fn( string $size = 'large' ): array => $group( 'media', [
|
||||
[ 'image', [ 'show_placeholder' => 'yes', 'image_size' => $size ] ],
|
||||
] );
|
||||
$excerpt = static fn( int $words ): array => [ 'excerpt', [ 'excerpt_words' => $words ] ];
|
||||
|
||||
$recipes = [
|
||||
'classic' => [
|
||||
'program' => [
|
||||
'title' => __( 'Program', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Wide photo, event details, and a button.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$photo(),
|
||||
$group( 'body', [ 'categories', 'schedule', 'title', 'venue', $excerpt( 24 ), 'link' ] ),
|
||||
],
|
||||
],
|
||||
'gazette' => [
|
||||
'title' => __( 'Gazette', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Editorial headline with a framed photo and venue address.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$group( 'body', [ 'categories', 'title', 'schedule', $excerpt( 20 ), 'address', 'link' ] ),
|
||||
$photo( 'medium_large' ),
|
||||
],
|
||||
],
|
||||
'invitation' => [
|
||||
'title' => __( 'Invitation', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Centered type with a date medallion and event details.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$group( 'body', [ 'date_badge', 'categories', 'title', 'venue', 'schedule', 'link' ] ),
|
||||
],
|
||||
],
|
||||
'ticket' => [
|
||||
'title' => __( 'Ticket', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Perforated date stub beside the title, venue, and price.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$group( 'rail', [ 'date_badge', 'cost' ] ),
|
||||
$group( 'body', [ 'categories', 'title', 'schedule', 'venue', 'link' ] ),
|
||||
],
|
||||
],
|
||||
],
|
||||
'minimal' => [
|
||||
'lineup' => [
|
||||
'title' => __( 'Lineup', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Date marker, title, and venue in a compact row.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$group( 'rail', [ 'date_badge' ] ),
|
||||
$group( 'body', [ 'title', 'time', 'venue', 'link' ] ),
|
||||
],
|
||||
],
|
||||
'bulletin' => [
|
||||
'title' => __( 'Bulletin', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Text-led card with a headline, schedule, and short description.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$group( 'body', [ 'categories', 'title', 'schedule', $excerpt( 19 ), 'link' ] ),
|
||||
],
|
||||
],
|
||||
'snapshot' => [
|
||||
'title' => __( 'Snapshot', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Small square photo beside the headline and schedule.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$photo( 'medium' ),
|
||||
$group( 'body', [ 'title', 'schedule', 'venue' ] ),
|
||||
],
|
||||
],
|
||||
'agenda' => [
|
||||
'title' => __( 'Agenda', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Schedule strip above a simple title and location.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$group( 'strip', [ 'schedule' ] ),
|
||||
$group( 'body', [ 'title', 'venue', 'address', 'link' ] ),
|
||||
],
|
||||
],
|
||||
],
|
||||
'modern' => [
|
||||
'cover' => [
|
||||
'title' => __( 'Cover', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Edge-to-edge photo with the title and schedule overlaid.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$photo(),
|
||||
$group( 'body', [ 'categories', 'title', 'schedule', 'venue', 'link' ] ),
|
||||
],
|
||||
],
|
||||
'split' => [
|
||||
'title' => __( 'Split', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Photo and a dark detail panel with event actions.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$photo(),
|
||||
$group( 'body', [
|
||||
'categories', 'title', 'schedule', 'venue', $excerpt( 18 ),
|
||||
$group( 'actions', [ 'link', 'share' ] ),
|
||||
] ),
|
||||
],
|
||||
],
|
||||
'panorama' => [
|
||||
'title' => __( 'Panorama', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Photo with a floating date badge and a light details panel.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$group( 'hero', [ $photo(), $group( 'badge', [ 'date_badge' ] ) ] ),
|
||||
$group( 'body', [ 'categories', 'title', 'schedule', 'venue', $group( 'actions', [ 'cost', 'link' ] ) ] ),
|
||||
],
|
||||
],
|
||||
'studio' => [
|
||||
'title' => __( 'Studio', 'eventlabs-loop-builder' ),
|
||||
'description' => __( 'Bold text card with a color accent, schedule, and price.', 'eventlabs-loop-builder' ),
|
||||
'parts' => [
|
||||
$group( 'strip', [ 'categories', 'status' ] ),
|
||||
$group( 'body', [ 'title', 'schedule', $excerpt( 22 ), 'organizer', $group( 'actions', [ 'cost', 'link' ] ) ] ),
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $recipes;
|
||||
}
|
||||
|
||||
private static function tree( string $slug ): array {
|
||||
$preset = self::catalog()[ $slug ] ?? null;
|
||||
if ( ! $preset ) {
|
||||
return [];
|
||||
}
|
||||
[ 'family' => $family, 'layout' => $layout, 'recipe' => $recipe ] = $preset;
|
||||
return [
|
||||
'classes' => "ell-preset ell-preset-family-$family ell-preset-layout-$layout ell-preset-style-$recipe",
|
||||
'children' => self::recipes()[ $family ][ $recipe ]['parts'],
|
||||
];
|
||||
}
|
||||
|
||||
private static function field( string|array $node ): array {
|
||||
return is_string( $node ) ? [ $node, [] ] : $node;
|
||||
}
|
||||
|
||||
private static function element( string|array $node, bool $inner = true ): array {
|
||||
$id = Utils::generate_random_string();
|
||||
if ( isset( $node['children'] ) ) {
|
||||
return [
|
||||
'id' => $id, 'elType' => 'container', 'isInner' => $inner,
|
||||
'settings' => [ 'content_width' => 'full', 'css_classes' => $node['classes'] ],
|
||||
'elements' => array_map( self::element( ... ), $node['children'] ),
|
||||
];
|
||||
}
|
||||
[ $key, $settings ] = self::field( $node );
|
||||
return [
|
||||
'id' => $id, 'elType' => 'widget', 'widgetType' => 'eventlabs-loop-field',
|
||||
'settings' => [ 'field' => $key ] + $settings,
|
||||
'elements' => [],
|
||||
];
|
||||
}
|
||||
|
||||
private static function markup( string|array $node, ?Card $card ): string {
|
||||
if ( isset( $node['children'] ) ) {
|
||||
$children = '';
|
||||
foreach ( $node['children'] as $child ) {
|
||||
$children .= self::markup( $child, $card );
|
||||
}
|
||||
return '' === $children ? '' : '<div class="' . esc_attr( $node['classes'] ) . '">' . $children . '</div>';
|
||||
}
|
||||
[ $key, $settings ] = self::field( $node );
|
||||
return $card ? $card->field( $key, $settings ) : self::sample_field( $key, $settings );
|
||||
}
|
||||
|
||||
private static function sample_field( string $key, array $settings ): string {
|
||||
switch ( $key ) {
|
||||
case 'image':
|
||||
return '<figure class="ell-field ell-image"><span class="ell-preset-sample-photo" aria-hidden="true"></span></figure>';
|
||||
case 'date_badge':
|
||||
return '<span class="ell-field ell-date-badge"><span class="ell-date-month">' . esc_html__( 'Jul', 'eventlabs-loop-builder' )
|
||||
. '</span><strong class="ell-date-day">18</strong><span class="ell-date-weekday">' . esc_html__( 'Sat', 'eventlabs-loop-builder' ) . '</span></span>';
|
||||
case 'categories':
|
||||
return '<div class="ell-field ell-categories"><span class="ell-chip">' . esc_html__( 'Live music', 'eventlabs-loop-builder' ) . '</span></div>';
|
||||
case 'title':
|
||||
return '<p class="ell-field ell-title">' . esc_html__( 'Music in the gardens', 'eventlabs-loop-builder' ) . '</p>';
|
||||
case 'schedule':
|
||||
return '<span class="ell-field ell-schedule">' . esc_html__( 'July 18 · 7:00 pm', 'eventlabs-loop-builder' ) . '</span>';
|
||||
case 'link':
|
||||
return '<span class="ell-field ell-link">' . esc_html__( 'View event', 'eventlabs-loop-builder' ) . '</span>';
|
||||
}
|
||||
|
||||
$label = match ( $key ) {
|
||||
'time' => __( '7:00 pm', 'eventlabs-loop-builder' ),
|
||||
'venue' => __( 'Botanical Garden', 'eventlabs-loop-builder' ),
|
||||
'address' => __( '24 Garden Lane', 'eventlabs-loop-builder' ),
|
||||
'organizer' => __( 'Garden Arts Collective', 'eventlabs-loop-builder' ),
|
||||
'excerpt' => wp_trim_words( __( 'An evening of live music among the garden paths and summer blooms.', 'eventlabs-loop-builder' ), $settings['excerpt_words'] ?? 25 ),
|
||||
'cost' => __( 'Free', 'eventlabs-loop-builder' ),
|
||||
'share' => __( 'Share', 'eventlabs-loop-builder' ),
|
||||
'status' => __( 'Featured', 'eventlabs-loop-builder' ),
|
||||
default => '',
|
||||
};
|
||||
return '' === $label ? '' : '<p class="ell-field ell-' . esc_attr( $key ) . '">' . esc_html( $label ) . '</p>';
|
||||
}
|
||||
}
|
||||
444
addons/eventlabs-loop-builder/includes/class-query.php
Normal file
444
addons/eventlabs-loop-builder/includes/class-query.php
Normal file
@@ -0,0 +1,444 @@
|
||||
<?php
|
||||
|
||||
namespace EventLabs\LoopBuilder;
|
||||
|
||||
use BurnEvents\Calendar;
|
||||
use BurnEvents\Clubs;
|
||||
use BurnEvents\Events;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use Elementor\Controls_Manager;
|
||||
use Elementor\Widget_Base;
|
||||
use WP_Post;
|
||||
use WP_Term;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
final class Query {
|
||||
private const PAGE_LIMIT = 10000;
|
||||
private const PAGE_SIZE = 50;
|
||||
private const PUBLIC_KEYS = [ 'search', 'category', 'tag', 'venue', 'organizer', 'city', 'country', 'when', 'start', 'end' ];
|
||||
|
||||
public static function controls( Widget_Base $widget ): void {
|
||||
$widget->add_control( 'source', [
|
||||
'label' => __( 'Source', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => [
|
||||
'manual' => __( 'Select filters below', 'eventlabs-loop-builder' ),
|
||||
'current' => __( 'Current event archive', 'eventlabs-loop-builder' ),
|
||||
'related' => __( 'Related to the current event', 'eventlabs-loop-builder' ),
|
||||
],
|
||||
'default' => 'manual',
|
||||
] );
|
||||
$widget->add_control( 'period', [
|
||||
'label' => __( 'Date scope', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => [
|
||||
'upcoming' => __( 'Upcoming and ongoing', 'eventlabs-loop-builder' ),
|
||||
'past' => __( 'Past events', 'eventlabs-loop-builder' ),
|
||||
'all' => __( 'All dates', 'eventlabs-loop-builder' ),
|
||||
'range' => __( 'Date range', 'eventlabs-loop-builder' ),
|
||||
] + self::periods(),
|
||||
'default' => 'upcoming',
|
||||
] );
|
||||
foreach ( [ 'date_from' => __( 'From date', 'eventlabs-loop-builder' ), 'date_to' => __( 'Through date', 'eventlabs-loop-builder' ) ] as $name => $label ) {
|
||||
$widget->add_control( $name, [
|
||||
'label' => $label, 'type' => Controls_Manager::DATE_TIME,
|
||||
'picker_options' => [ 'enableTime' => false, 'dateFormat' => 'Y-m-d' ],
|
||||
'condition' => [ 'period' => 'range' ],
|
||||
] );
|
||||
}
|
||||
$widget->add_control( 'order', [
|
||||
'label' => __( 'Date order', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => [ '' => __( 'Automatic', 'eventlabs-loop-builder' ), 'ASC' => __( 'Earliest first', 'eventlabs-loop-builder' ), 'DESC' => __( 'Latest first', 'eventlabs-loop-builder' ) ],
|
||||
'default' => '',
|
||||
] );
|
||||
$widget->add_control( 'per_page', [
|
||||
'label' => __( 'Occurrences per page', 'eventlabs-loop-builder' ),
|
||||
'type' => Controls_Manager::NUMBER, 'min' => 1, 'max' => self::PAGE_SIZE, 'default' => 6,
|
||||
] );
|
||||
$widget->add_control( 'offset', [
|
||||
'label' => __( 'Skip the first occurrences', 'eventlabs-loop-builder' ),
|
||||
'type' => Controls_Manager::NUMBER, 'min' => 0, 'max' => self::PAGE_LIMIT, 'default' => 0,
|
||||
] );
|
||||
$widget->add_control( 'category', [
|
||||
'label' => __( 'Categories', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT2,
|
||||
'options' => self::terms( Events::CATEGORY ), 'default' => [], 'multiple' => true,
|
||||
] );
|
||||
$widget->add_control( 'tag', [
|
||||
'label' => __( 'Tags', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT2,
|
||||
'options' => self::terms( 'post_tag' ), 'default' => [], 'multiple' => true,
|
||||
] );
|
||||
foreach ( self::relation_labels() as $type => $label ) {
|
||||
$widget->add_control( $type . '_ids', [
|
||||
'label' => $label, 'type' => Controls_Manager::SELECT2, 'multiple' => true, 'default' => [],
|
||||
'options' => self::linked_options( Events::RELATIONS[ $type ] ),
|
||||
] );
|
||||
}
|
||||
foreach ( [ 'city' => __( 'Cities', 'eventlabs-loop-builder' ), 'country' => __( 'Countries', 'eventlabs-loop-builder' ) ] as $field => $label ) {
|
||||
$widget->add_control( $field, [
|
||||
'label' => $label, 'type' => Controls_Manager::SELECT2, 'multiple' => true, 'default' => [],
|
||||
'options' => self::places( $field ),
|
||||
] );
|
||||
}
|
||||
$widget->add_control( 'scope', [
|
||||
'label' => __( 'Club or sub-club', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT2,
|
||||
'options' => Clubs::options(), 'default' => '',
|
||||
] );
|
||||
$widget->add_control( 'keyword', [ 'label' => __( 'Keyword', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::TEXT ] );
|
||||
$widget->add_control( 'featured', [
|
||||
'label' => __( 'Event type', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT, 'default' => '',
|
||||
'options' => [ '' => __( 'All events', 'eventlabs-loop-builder' ), 'yes' => __( 'Featured events', 'eventlabs-loop-builder' ), 'regular' => __( 'Non-featured events', 'eventlabs-loop-builder' ) ],
|
||||
] );
|
||||
$widget->add_control( 'empty_message', [
|
||||
'label' => __( 'Empty message', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::TEXT,
|
||||
'default' => __( 'No events match these filters.', 'eventlabs-loop-builder' ),
|
||||
] );
|
||||
}
|
||||
|
||||
public static function filter_controls( Widget_Base $widget ): void {
|
||||
$widget->add_control( 'public_filters', [
|
||||
'label' => __( 'Show visitor filters', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SWITCHER,
|
||||
'description' => __( 'Visitor selections stay within the Event Query filters.', 'eventlabs-loop-builder' ),
|
||||
] );
|
||||
$widget->add_control( 'filter_fields', [
|
||||
'label' => __( 'Visitor controls', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT2,
|
||||
'multiple' => true, 'default' => [ 'search', 'category' ], 'condition' => [ 'public_filters' => 'yes' ],
|
||||
'options' => [
|
||||
'search' => __( 'Search', 'eventlabs-loop-builder' ), 'category' => __( 'Category', 'eventlabs-loop-builder' ),
|
||||
'tag' => __( 'Tag', 'eventlabs-loop-builder' ), 'venue' => __( 'Venue', 'eventlabs-loop-builder' ),
|
||||
'organizer' => __( 'Organizer', 'eventlabs-loop-builder' ), 'city' => __( 'City', 'eventlabs-loop-builder' ),
|
||||
'country' => __( 'Country', 'eventlabs-loop-builder' ), 'date' => __( 'Date', 'eventlabs-loop-builder' ),
|
||||
],
|
||||
] );
|
||||
}
|
||||
|
||||
private static function periods(): array {
|
||||
return [
|
||||
'today' => __( 'Today', 'eventlabs-loop-builder' ), 'tomorrow' => __( 'Tomorrow', 'eventlabs-loop-builder' ),
|
||||
'week' => __( 'This week', 'eventlabs-loop-builder' ), 'next_week' => __( 'Next week', 'eventlabs-loop-builder' ),
|
||||
'weekend' => __( 'This weekend', 'eventlabs-loop-builder' ), 'next_weekend' => __( 'Next weekend', 'eventlabs-loop-builder' ),
|
||||
'month' => __( 'This month', 'eventlabs-loop-builder' ), 'next_month' => __( 'Next month', 'eventlabs-loop-builder' ),
|
||||
];
|
||||
}
|
||||
|
||||
private static function relation_labels(): array {
|
||||
return [ 'venue' => __( 'Venues', 'eventlabs-loop-builder' ), 'organizer' => __( 'Organizers', 'eventlabs-loop-builder' ), 'series' => __( 'Series', 'eventlabs-loop-builder' ) ];
|
||||
}
|
||||
|
||||
public static function results( array $settings, string $instance, bool $editing ): array {
|
||||
$result = [ 'rows' => [], 'page' => 1, 'previous' => '', 'next' => '', 'filters' => '', 'error' => '' ];
|
||||
$prefix = 'el_loop_' . $instance . '_';
|
||||
$anchor = '#eventlabs-loop-' . $instance;
|
||||
$pagination = ! $editing && 'none' !== self::pagination( $settings );
|
||||
$page = $pagination ? max( 1, min( self::PAGE_LIMIT, absint( Calendar::request( $prefix . 'page' ) ) ) ) : 1;
|
||||
$limit = max( 1, min( self::PAGE_SIZE, absint( $settings['per_page'] ?? 6 ) ) );
|
||||
$result['page'] = $page;
|
||||
$period = $settings['period'] ?? 'upcoming';
|
||||
$now = gmdate( 'Y-m-d H:i:s' );
|
||||
[ $from, $to, $invalid_range ] = self::date_range( (string) $period, (string) ( $settings['date_from'] ?? '' ), (string) ( $settings['date_to'] ?? '' ) );
|
||||
if ( 'upcoming' === $period ) {
|
||||
$from = $now;
|
||||
}
|
||||
|
||||
$public = ! $editing && 'yes' === ( $settings['public_filters'] ?? '' ) ? (array) ( $settings['filter_fields'] ?? [ 'search', 'category' ] ) : [];
|
||||
$public_options = self::public_options( $public );
|
||||
$visitor = [];
|
||||
foreach ( array_keys( $public_options ) as $key ) {
|
||||
$value = wp_html_excerpt( Calendar::request( $prefix . $key ), 200 );
|
||||
if ( '' !== $value ) {
|
||||
$visitor[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
$keyword = wp_html_excerpt( (string) ( $settings['keyword'] ?? '' ), 200 );
|
||||
if ( '' !== $keyword ) {
|
||||
unset( $public_options['search'], $visitor['search'] );
|
||||
}
|
||||
|
||||
$categories = self::keys( $settings['category'] ?? [] );
|
||||
$tags = self::keys( $settings['tag'] ?? [] );
|
||||
$relations = [];
|
||||
foreach ( Events::RELATIONS as $type => $post_type ) {
|
||||
$relations[ $type ] = self::ids( $settings[ $type . '_ids' ] ?? [] );
|
||||
}
|
||||
$legacy_type = (string) ( $settings['relation_type'] ?? '' );
|
||||
if ( isset( Events::RELATIONS[ $legacy_type ] ) && ! $relations[ $legacy_type ] ) {
|
||||
$relations[ $legacy_type ] = self::ids( $settings[ $legacy_type . '_id' ] ?? [] );
|
||||
}
|
||||
|
||||
$exclude = 0;
|
||||
$source = $settings['source'] ?? 'manual';
|
||||
$object = 'manual' === $source ? null : get_queried_object();
|
||||
$source_error = '';
|
||||
if ( 'current' === $source ) {
|
||||
if ( $object instanceof WP_Term && Events::CATEGORY === $object->taxonomy ) {
|
||||
$categories = self::restrict( $categories, [ $object->slug ] );
|
||||
} elseif ( $object instanceof WP_Post && ( $type = array_search( $object->post_type, Events::RELATIONS, true ) ) ) {
|
||||
$relations[ $type ] = self::restrict( $relations[ $type ], [ $object->ID ] );
|
||||
} elseif ( ! is_post_type_archive( Events::EVENT ) ) {
|
||||
$source_error = __( 'Current event archive needs an event category, venue, organizer, series, or events archive.', 'eventlabs-loop-builder' );
|
||||
}
|
||||
}
|
||||
if ( 'related' === $source ) {
|
||||
$related = $object instanceof WP_Post && Events::EVENT === $object->post_type ? wp_get_post_terms( $object->ID, Events::CATEGORY, [ 'fields' => 'slugs' ] ) : [];
|
||||
if ( is_array( $related ) && $related ) {
|
||||
$categories = self::restrict( $categories, $related );
|
||||
$exclude = $object->ID;
|
||||
} else {
|
||||
$source_error = __( 'Related events need an event page with at least one event category.', 'eventlabs-loop-builder' );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( [ 'category', 'tag', 'venue', 'organizer', 'city', 'country' ] as $key ) {
|
||||
if ( isset( $visitor[ $key ] ) && ! isset( $public_options[ $key ]['options'][ $visitor[ $key ] ] ) ) {
|
||||
unset( $visitor[ $key ] );
|
||||
}
|
||||
}
|
||||
$categories = self::restrict( $categories, isset( $visitor['category'] ) ? [ $visitor['category'] ] : [] );
|
||||
$tags = self::restrict( $tags, isset( $visitor['tag'] ) ? [ $visitor['tag'] ] : [] );
|
||||
foreach ( [ 'venue', 'organizer' ] as $type ) {
|
||||
if ( isset( $visitor[ $type ] ) ) {
|
||||
$relations[ $type ] = self::restrict( $relations[ $type ], [ absint( $visitor[ $type ] ) ] );
|
||||
}
|
||||
}
|
||||
|
||||
$cities = self::restrict( self::keys( $settings['city'] ?? [] ), isset( $visitor['city'] ) ? [ $visitor['city'] ] : [] );
|
||||
$countries = self::restrict( self::keys( $settings['country'] ?? [] ), isset( $visitor['country'] ) ? [ $visitor['country'] ] : [] );
|
||||
if ( false !== $cities && false !== $countries && ( $cities || $countries ) ) {
|
||||
$matching = [];
|
||||
foreach ( self::linked_posts( Events::VENUE ) as $venue ) {
|
||||
$data = Events::location_data( $venue->ID );
|
||||
if ( ( ! $cities || in_array( sanitize_title( $data['city'] ), $cities, true ) ) && ( ! $countries || in_array( sanitize_title( $data['country'] ), $countries, true ) ) ) {
|
||||
$matching[] = $venue->ID;
|
||||
}
|
||||
}
|
||||
$relations['venue'] = $matching ? self::restrict( $relations['venue'], $matching ) : false;
|
||||
}
|
||||
$when = $visitor['when'] ?? '';
|
||||
if ( ! isset( self::periods()[ $when ] ) ) {
|
||||
unset( $visitor['when'] );
|
||||
$when = isset( $visitor['start'] ) || isset( $visitor['end'] ) ? 'range' : '';
|
||||
} else {
|
||||
unset( $visitor['start'], $visitor['end'] );
|
||||
}
|
||||
[ $visitor_from, $visitor_to, $visitor_error ] = self::date_range( $when, $visitor['start'] ?? '', $visitor['end'] ?? '' );
|
||||
$from = $from && $visitor_from ? max( $from, $visitor_from ) : ( $from ?: $visitor_from );
|
||||
$to = $to && $visitor_to ? min( $to, $visitor_to ) : ( $to ?: $visitor_to );
|
||||
$invalid = $invalid_range || $visitor_error || ( $from && $to && $from >= $to ) || in_array( false, [ ...array_values( $relations ), $categories, $tags, $cities, $countries ], true );
|
||||
$past = 'past' === $period;
|
||||
if ( $invalid_range || $source_error ) {
|
||||
$result['error'] = $source_error ?: __( 'Enter a valid date range for this loop.', 'eventlabs-loop-builder' );
|
||||
}
|
||||
|
||||
if ( ! $invalid && ! $source_error ) {
|
||||
$rows = Events::query( [
|
||||
'from' => $from, 'to' => $to, 'end_by' => $past ? $now : null,
|
||||
'order' => ( $settings['order'] ?? '' ) ?: ( $past ? 'DESC' : 'ASC' ),
|
||||
'search' => $keyword ?: ( $visitor['search'] ?? '' ), 'category' => $categories, 'tag' => $tags, 'relations' => $relations,
|
||||
'scope' => sanitize_text_field( (string) ( $settings['scope'] ?? '' ) ),
|
||||
'featured' => $settings['featured'] ?? '', 'exclude' => $exclude,
|
||||
'offset' => ( $page - 1 ) * $limit + min( self::PAGE_LIMIT, absint( $settings['offset'] ?? 0 ) ),
|
||||
'limit' => $pagination ? $limit + 1 : $limit,
|
||||
] );
|
||||
} else {
|
||||
$rows = [];
|
||||
}
|
||||
$result['rows'] = array_slice( $rows, 0, $limit );
|
||||
$has_next = $pagination && $page < self::PAGE_LIMIT && count( $rows ) > $limit;
|
||||
if ( $page === 1 && ! $has_next && ! $public_options ) {
|
||||
return $result;
|
||||
}
|
||||
[ $url, $state ] = self::page_state( $prefix );
|
||||
$filters = [];
|
||||
foreach ( $visitor as $key => $value ) {
|
||||
$filters[ $prefix . $key ] = $value;
|
||||
}
|
||||
if ( $public_options ) {
|
||||
$result['filters'] = self::filter_form( $url, $state, $anchor, $prefix, $public_options, $visitor, $visitor_error );
|
||||
}
|
||||
$state += $filters;
|
||||
if ( $page > 1 ) {
|
||||
$result['previous'] = self::url( $url, $page > 2 ? $state + [ $prefix . 'page' => $page - 1 ] : $state, $anchor );
|
||||
}
|
||||
if ( $has_next ) {
|
||||
$result['next'] = self::url( $url, $state + [ $prefix . 'page' => $page + 1 ], $anchor );
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function pagination( array $settings ): string {
|
||||
if ( isset( $settings['pagination_mode'] ) && in_array( $settings['pagination_mode'], [ 'links', 'more', 'none' ], true ) ) {
|
||||
return $settings['pagination_mode'];
|
||||
}
|
||||
return 'yes' === ( $settings['pagination'] ?? 'yes' ) ? 'links' : 'none';
|
||||
}
|
||||
|
||||
private static function restrict( array|false $values, array $subset ): array|false {
|
||||
if ( false === $values || ! $subset ) {
|
||||
return $values;
|
||||
}
|
||||
return $values ? ( array_values( array_intersect( $values, $subset ) ) ?: false ) : $subset;
|
||||
}
|
||||
|
||||
private static function keys( $values ): array {
|
||||
return array_values( array_filter( array_map( 'sanitize_title', array_filter( (array) $values, 'is_string' ) ), 'strlen' ) );
|
||||
}
|
||||
|
||||
private static function ids( $values ): array {
|
||||
return array_values( array_filter( array_map( 'absint', array_filter( (array) $values, 'is_scalar' ) ) ) );
|
||||
}
|
||||
|
||||
private static function date_range( string $period, string $from, string $to ): array {
|
||||
$today = current_datetime()->setTime( 0, 0 );
|
||||
$week = $today->modify( '-' . ( ( (int) $today->format( 'w' ) - (int) get_option( 'start_of_week' ) + 7 ) % 7 ) . ' days' );
|
||||
$saturday = $today->modify( 0 === (int) $today->format( 'w' ) ? '-1 day' : '+' . ( 6 - (int) $today->format( 'w' ) ) . ' days' );
|
||||
$month = $today->modify( 'first day of this month' );
|
||||
$error = false;
|
||||
[ $start, $end ] = match ( $period ) {
|
||||
'today' => [ $today, $today->modify( '+1 day' ) ],
|
||||
'tomorrow' => [ $today->modify( '+1 day' ), $today->modify( '+2 days' ) ],
|
||||
'week' => [ $week, $week->modify( '+7 days' ) ],
|
||||
'next_week' => [ $week->modify( '+7 days' ), $week->modify( '+14 days' ) ],
|
||||
'weekend' => [ $saturday, $saturday->modify( '+2 days' ) ],
|
||||
'next_weekend' => [ $saturday->modify( '+7 days' ), $saturday->modify( '+9 days' ) ],
|
||||
'month' => [ $month, $month->modify( '+1 month' ) ],
|
||||
'next_month' => [ $month->modify( '+1 month' ), $month->modify( '+2 months' ) ],
|
||||
'range' => [ self::date( $from ), self::date( $to )?->modify( '+1 day' ) ],
|
||||
default => [ null, null ],
|
||||
};
|
||||
if ( 'range' === $period ) {
|
||||
$error = ( ! $start && ! $end ) || ( '' !== $from && ! $start ) || ( '' !== $to && ! $end ) || ( $start && $end && $start >= $end );
|
||||
}
|
||||
$utc = new DateTimeZone( 'UTC' );
|
||||
return [ $start?->setTimezone( $utc )->format( 'Y-m-d H:i:s' ), $end?->setTimezone( $utc )->format( 'Y-m-d H:i:s' ), $error ];
|
||||
}
|
||||
|
||||
private static function date( string $value ): ?DateTimeImmutable {
|
||||
if ( ! preg_match( '/^\d{4}-\d{2}-\d{2}$/D', $value ) ) {
|
||||
return null;
|
||||
}
|
||||
$date = DateTimeImmutable::createFromFormat( '!Y-m-d', $value, wp_timezone() );
|
||||
return $date && $date->format( 'Y-m-d' ) === $value ? $date : null;
|
||||
}
|
||||
|
||||
private static function terms( string $taxonomy, bool $hide_empty = false ): array {
|
||||
$terms = get_terms( [ 'taxonomy' => $taxonomy, 'hide_empty' => $hide_empty ] );
|
||||
$options = [];
|
||||
foreach ( is_array( $terms ) ? $terms : [] as $term ) {
|
||||
$options[ $term->slug ] = $term->name;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
private static function linked_posts( string $type ): array {
|
||||
static $posts = [];
|
||||
return $posts[ $type ] ??= get_posts( [
|
||||
'post_type' => $type, 'post_status' => 'publish', 'has_password' => false, 'posts_per_page' => -1,
|
||||
'orderby' => [ 'title' => 'ASC', 'ID' => 'ASC' ], 'update_post_meta_cache' => Events::VENUE === $type, 'update_post_term_cache' => false,
|
||||
] );
|
||||
}
|
||||
|
||||
private static function linked_options( string $type ): array {
|
||||
$options = [];
|
||||
foreach ( self::linked_posts( $type ) as $post ) {
|
||||
$options[ $post->ID ] = get_the_title( $post );
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
private static function places( string $field ): array {
|
||||
$options = [];
|
||||
foreach ( self::linked_posts( Events::VENUE ) as $venue ) {
|
||||
$value = Events::location_data( $venue->ID )[ $field ];
|
||||
if ( $value ) {
|
||||
$options[ sanitize_title( $value ) ] = $value;
|
||||
}
|
||||
}
|
||||
natcasesort( $options );
|
||||
return $options;
|
||||
}
|
||||
|
||||
private static function public_options( array $fields ): array {
|
||||
$options = [];
|
||||
foreach ( array_unique( $fields, SORT_REGULAR ) as $field ) {
|
||||
$options += match ( $field ) {
|
||||
'search' => [ 'search' => [ 'label' => __( 'Search events', 'eventlabs-loop-builder' ), 'type' => 'search' ] ],
|
||||
'category' => [ 'category' => [ 'label' => __( 'Category', 'eventlabs-loop-builder' ), 'options' => [ '' => __( 'All categories', 'eventlabs-loop-builder' ) ] + self::terms( Events::CATEGORY, true ) ] ],
|
||||
'tag' => [ 'tag' => [ 'label' => __( 'Tag', 'eventlabs-loop-builder' ), 'options' => [ '' => __( 'All tags', 'eventlabs-loop-builder' ) ] + self::terms( 'post_tag', true ) ] ],
|
||||
'venue' => [ 'venue' => [ 'label' => __( 'Venue', 'eventlabs-loop-builder' ), 'options' => [ '' => __( 'All venues', 'eventlabs-loop-builder' ) ] + self::linked_options( Events::VENUE ) ] ],
|
||||
'organizer' => [ 'organizer' => [ 'label' => __( 'Organizer', 'eventlabs-loop-builder' ), 'options' => [ '' => __( 'All organizers', 'eventlabs-loop-builder' ) ] + self::linked_options( Events::ORGANIZER ) ] ],
|
||||
'city' => [ 'city' => [ 'label' => __( 'City', 'eventlabs-loop-builder' ), 'options' => [ '' => __( 'All cities', 'eventlabs-loop-builder' ) ] + self::places( 'city' ) ] ],
|
||||
'country' => [ 'country' => [ 'label' => __( 'Country', 'eventlabs-loop-builder' ), 'options' => [ '' => __( 'All countries', 'eventlabs-loop-builder' ) ] + self::places( 'country' ) ] ],
|
||||
'date' => [
|
||||
'when' => [ 'label' => __( 'Date', 'eventlabs-loop-builder' ), 'options' => [ '' => __( 'Any date or use range', 'eventlabs-loop-builder' ) ] + self::periods() ],
|
||||
'start' => [ 'label' => __( 'From date', 'eventlabs-loop-builder' ), 'type' => 'date' ],
|
||||
'end' => [ 'label' => __( 'Through date', 'eventlabs-loop-builder' ), 'type' => 'date' ],
|
||||
],
|
||||
default => [],
|
||||
};
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
private static function page_state( string $prefix ): array {
|
||||
$url = get_pagenum_link( max( 1, absint( get_query_var( 'paged' ) ) ), false );
|
||||
parse_str( (string) wp_parse_url( $url, PHP_URL_QUERY ), $params );
|
||||
$route = [ 'page_id', 'p', 'page', 'paged', 'post_type', 'name', 'pagename', 's', 'cat', 'tag', 'taxonomy', 'term', 'author', 'year', 'monthnum', 'day', 'lang', 'be_occ' ];
|
||||
$object = get_queried_object();
|
||||
$type = $object instanceof WP_Term ? get_taxonomy( $object->taxonomy ) : ( $object instanceof WP_Post ? get_post_type_object( $object->post_type ) : null );
|
||||
if ( $type && $type->query_var ) {
|
||||
$route[] = $type->query_var;
|
||||
}
|
||||
$state = array_filter( array_intersect_key( $params, array_flip( $route ) ), 'is_string' );
|
||||
$keys = implode( '|', [ ...self::PUBLIC_KEYS, 'page' ] );
|
||||
$own_keys = array_map( static fn( string $key ): string => $prefix . $key, [ ...self::PUBLIC_KEYS, 'page' ] );
|
||||
foreach ( array_keys( $_GET ) as $key ) {
|
||||
if ( is_string( $key ) && ! in_array( $key, $own_keys, true ) && preg_match( '/^el_loop_[a-z0-9_-]{1,80}_(?:' . $keys . ')$/D', $key ) ) {
|
||||
$value = wp_html_excerpt( Calendar::request( $key ), 200 );
|
||||
if ( '' !== $value ) {
|
||||
$state[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [ explode( '?', $url, 2 )[0], $state ];
|
||||
}
|
||||
|
||||
private static function url( string $base, array $state, string $anchor ): string {
|
||||
$query = http_build_query( $state, '', '&', PHP_QUERY_RFC3986 );
|
||||
return $base . ( '' === $query ? '' : '?' . $query ) . $anchor;
|
||||
}
|
||||
|
||||
private static function filter_form( string $url, array $state, string $anchor, string $prefix, array $controls, array $values, bool $error ): string {
|
||||
ob_start();
|
||||
?>
|
||||
<form class="el-loop-filters" action="<?php echo esc_url( $url . $anchor ); ?>" method="get" aria-label="<?php esc_attr_e( 'Filter events', 'eventlabs-loop-builder' ); ?>">
|
||||
<?php foreach ( $state as $name => $value ) : ?>
|
||||
<input type="hidden" name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $value ); ?>">
|
||||
<?php endforeach; ?>
|
||||
<?php if ( $error ) : ?>
|
||||
<p class="ell-filter-error" role="alert"><?php esc_html_e( 'Enter a valid date range.', 'eventlabs-loop-builder' ); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php foreach ( $controls as $key => $control ) : ?>
|
||||
<?php $name = $prefix . $key; ?>
|
||||
<div class="el-loop-filter-field">
|
||||
<label for="<?php echo esc_attr( $name ); ?>"><?php echo esc_html( $control['label'] ); ?></label>
|
||||
<?php if ( isset( $control['options'] ) ) : ?>
|
||||
<select id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?>">
|
||||
<?php foreach ( $control['options'] as $value => $label ) : ?>
|
||||
<option value="<?php echo esc_attr( (string) $value ); ?>" <?php selected( $values[ $key ] ?? '', $value ); ?>><?php echo esc_html( $label ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php else : ?>
|
||||
<input type="<?php echo esc_attr( $control['type'] ); ?>" id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $values[ $key ] ?? '' ); ?>" maxlength="200">
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<div class="el-loop-filter-actions">
|
||||
<button type="submit"><?php esc_html_e( 'Filter', 'eventlabs-loop-builder' ); ?></button>
|
||||
<?php if ( $values ) : ?>
|
||||
<a href="<?php echo esc_url( self::url( $url, $state, $anchor ) ); ?>"><?php esc_html_e( 'Clear filters', 'eventlabs-loop-builder' ); ?></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</form>
|
||||
<?php
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
}
|
||||
94
addons/eventlabs-loop-builder/includes/class-tags.php
Normal file
94
addons/eventlabs-loop-builder/includes/class-tags.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace EventLabs\LoopBuilder;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use Elementor\Core\DynamicTags\Data_Tag;
|
||||
use Elementor\Core\DynamicTags\Tag;
|
||||
use Elementor\Modules\DynamicTags\Module;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
final class Field_Tag extends Tag {
|
||||
public function get_name(): string {
|
||||
return 'eventlabs-loop-event-field';
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return __( 'Loop event field', 'eventlabs-loop-builder' );
|
||||
}
|
||||
|
||||
public function get_group(): string {
|
||||
return ASSET;
|
||||
}
|
||||
|
||||
public function get_categories(): array {
|
||||
return [ Module::TEXT_CATEGORY ];
|
||||
}
|
||||
|
||||
protected function register_controls(): void {
|
||||
$this->add_control( 'field', [
|
||||
'label' => __( 'Event field', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => Card::text_fields(), 'default' => 'title',
|
||||
] );
|
||||
$this->add_control( 'custom_key', [
|
||||
'label' => __( 'Custom field', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => Card::custom_fields(), 'condition' => [ 'field' => 'custom' ],
|
||||
] );
|
||||
}
|
||||
|
||||
public function render(): void {
|
||||
$card = Templates::active_card();
|
||||
if ( $card ) {
|
||||
echo esc_html( $card->value( (string) $this->get_settings( 'field' ), (string) $this->get_settings( 'custom_key' ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class Link_Tag extends Tag {
|
||||
public function get_name(): string {
|
||||
return 'eventlabs-loop-event-link';
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return __( 'Loop event link', 'eventlabs-loop-builder' );
|
||||
}
|
||||
|
||||
public function get_group(): string {
|
||||
return ASSET;
|
||||
}
|
||||
|
||||
public function get_categories(): array {
|
||||
return [ Module::URL_CATEGORY ];
|
||||
}
|
||||
|
||||
public function render(): void {
|
||||
$card = Templates::active_card();
|
||||
if ( $card ) {
|
||||
echo esc_url_raw( $card->link() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class Image_Tag extends Data_Tag {
|
||||
public function get_name(): string {
|
||||
return 'eventlabs-loop-event-image';
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return __( 'Loop event image', 'eventlabs-loop-builder' );
|
||||
}
|
||||
|
||||
public function get_group(): string {
|
||||
return ASSET;
|
||||
}
|
||||
|
||||
public function get_categories(): array {
|
||||
return [ Module::IMAGE_CATEGORY ];
|
||||
}
|
||||
|
||||
protected function get_value( array $options = [] ): array {
|
||||
$card = Templates::active_card();
|
||||
return $card ? $card->image() : [ 'id' => 0, 'url' => '' ];
|
||||
}
|
||||
}
|
||||
306
addons/eventlabs-loop-builder/includes/class-templates.php
Normal file
306
addons/eventlabs-loop-builder/includes/class-templates.php
Normal file
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
|
||||
namespace EventLabs\LoopBuilder;
|
||||
|
||||
use BurnEvents\Events;
|
||||
use Elementor\Core\Base\Document;
|
||||
use Elementor\Plugin as Elementor;
|
||||
use WP_Post;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
final class Templates {
|
||||
public const POST_TYPE = 'eventlabs_loop_item';
|
||||
public const CAPABILITY = 'edit_theme_options';
|
||||
public const LAYOUT_META = '_eventlabs_loop_layout';
|
||||
public const STARTER_ACTION = 'eventlabs_loop_create_starter';
|
||||
private const PREVIEW_META = '_eventlabs_loop_preview_event';
|
||||
private const PREVIEW_NONCE = 'eventlabs_loop_preview_nonce';
|
||||
private const PREVIEW_ACTION = 'eventlabs_loop_save_preview';
|
||||
|
||||
private static ?Card $card = null;
|
||||
private static array $preview_cards = [];
|
||||
|
||||
public static function register(): void {
|
||||
add_action( 'init', [ self::class, 'register_type' ], 11 );
|
||||
add_action( 'template_redirect', [ self::class, 'protect_preview' ], 0 );
|
||||
add_action( 'add_meta_boxes_' . self::POST_TYPE, [ self::class, 'add_preview_box' ] );
|
||||
add_action( 'save_post_' . self::POST_TYPE, [ self::class, 'save_preview' ] );
|
||||
add_action( 'manage_' . self::POST_TYPE . '_posts_custom_column', [ self::class, 'layout_column' ], 10, 2 );
|
||||
add_filter( 'manage_' . self::POST_TYPE . '_posts_columns', [ self::class, 'columns' ] );
|
||||
add_filter( 'post_row_actions', [ self::class, 'row_actions' ], 10, 2 );
|
||||
add_action( 'admin_post_' . self::STARTER_ACTION, [ self::class, 'create_starter' ] );
|
||||
add_action( 'admin_post_eventlabs_loop_duplicate', [ self::class, 'duplicate' ] );
|
||||
add_filter( 'plugin_action_links_' . plugin_basename( FILE ), [ self::class, 'links' ] );
|
||||
}
|
||||
|
||||
public static function register_type(): void {
|
||||
register_post_type( self::POST_TYPE, [
|
||||
'labels' => [
|
||||
'name' => __( 'Loop Templates', 'eventlabs-loop-builder' ),
|
||||
'singular_name' => __( 'Loop Template', 'eventlabs-loop-builder' ),
|
||||
'add_new' => __( 'Add Loop Template', 'eventlabs-loop-builder' ),
|
||||
'add_new_item' => __( 'Add Loop Template', 'eventlabs-loop-builder' ),
|
||||
'edit_item' => __( 'Edit Loop Template', 'eventlabs-loop-builder' ),
|
||||
'view_item' => __( 'Preview Loop Template', 'eventlabs-loop-builder' ),
|
||||
'search_items' => __( 'Search loop templates', 'eventlabs-loop-builder' ),
|
||||
'not_found' => __( 'No loop templates found.', 'eventlabs-loop-builder' ),
|
||||
],
|
||||
'public' => false,
|
||||
'publicly_queryable' => true,
|
||||
'exclude_from_search' => true,
|
||||
'show_ui' => true,
|
||||
'show_in_menu' => 'edit.php?post_type=' . Events::EVENT,
|
||||
'show_in_nav_menus' => false,
|
||||
'show_in_admin_bar' => false,
|
||||
'rewrite' => false,
|
||||
'map_meta_cap' => false,
|
||||
'capabilities' => array_fill_keys( [
|
||||
'edit_post', 'read_post', 'delete_post', 'edit_posts', 'edit_others_posts', 'publish_posts',
|
||||
'read_private_posts', 'create_posts', 'edit_private_posts', 'edit_published_posts',
|
||||
'delete_posts', 'delete_private_posts', 'delete_others_posts', 'delete_published_posts',
|
||||
], self::CAPABILITY ),
|
||||
'supports' => [ 'title', 'editor', 'revisions', 'elementor' ],
|
||||
] );
|
||||
}
|
||||
|
||||
public static function protect_preview(): void {
|
||||
$singular = is_singular( self::POST_TYPE );
|
||||
if ( ! $singular && ! in_array( self::POST_TYPE, (array) get_query_var( 'post_type' ), true ) ) {
|
||||
return;
|
||||
}
|
||||
nocache_headers();
|
||||
if ( ! $singular || ! current_user_can( 'edit_post', get_queried_object_id() ) ) {
|
||||
wp_die( esc_html__( 'Page not found.', 'eventlabs-loop-builder' ), '', [ 'response' => 404 ] );
|
||||
}
|
||||
}
|
||||
|
||||
public static function links( array $links ): array {
|
||||
if ( current_user_can( self::CAPABILITY ) ) {
|
||||
$links[] = '<a href="' . esc_url( admin_url( 'edit.php?post_type=' . self::POST_TYPE ) ) . '">'
|
||||
. esc_html__( 'Loop Templates', 'eventlabs-loop-builder' ) . '</a>';
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
|
||||
public static function is_editing(): bool {
|
||||
$elementor = Elementor::instance();
|
||||
return $elementor->editor->is_edit_mode() || $elementor->preview->is_preview_mode();
|
||||
}
|
||||
|
||||
private static function is_template( ?WP_Post $post ): bool {
|
||||
return $post && self::POST_TYPE === $post->post_type;
|
||||
}
|
||||
|
||||
public static function current_template(): ?WP_Post {
|
||||
$post = get_post();
|
||||
if ( self::is_template( $post ) ) {
|
||||
return $post;
|
||||
}
|
||||
$document = Elementor::instance()->documents->get_current();
|
||||
$post = $document ? $document->get_main_post() : null;
|
||||
return self::is_template( $post ) ? $post : null;
|
||||
}
|
||||
|
||||
public static function active_card(): ?Card {
|
||||
if ( self::$card ) {
|
||||
return self::$card;
|
||||
}
|
||||
|
||||
$template = self::current_template();
|
||||
if ( ! $template || ! current_user_can( 'edit_post', $template->ID ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( ! array_key_exists( $template->ID, self::$preview_cards ) ) {
|
||||
self::$preview_cards[ $template->ID ] = self::preview_card( $template->ID );
|
||||
}
|
||||
return self::$preview_cards[ $template->ID ];
|
||||
}
|
||||
|
||||
public static function is_rendering_card(): bool {
|
||||
return null !== self::$card;
|
||||
}
|
||||
|
||||
private static function preview_card( int $template_id ): ?Card {
|
||||
$id = (int) get_post_meta( $template_id, self::PREVIEW_META, true );
|
||||
$event = $id ? get_post( $id ) : null;
|
||||
if ( self::is_preview_event( $event ) ) {
|
||||
return new Card( $event, Events::occurrence( $id ) );
|
||||
}
|
||||
|
||||
$row = Events::query( [ 'from' => gmdate( 'Y-m-d H:i:s' ), 'limit' => 1 ] )[0] ?? null;
|
||||
$event = $row ? get_post( (int) $row['event_id'] ) : null;
|
||||
if ( self::is_preview_event( $event ) ) {
|
||||
return new Card( $event, $row );
|
||||
}
|
||||
|
||||
$event = self::recent_events( 1 )[0] ?? null;
|
||||
return $event ? new Card( $event, Events::occurrence( $event->ID ) ) : null;
|
||||
}
|
||||
|
||||
private static function is_preview_event( ?WP_Post $event ): bool {
|
||||
return $event && Events::EVENT === $event->post_type && 'publish' === $event->post_status && '' === $event->post_password;
|
||||
}
|
||||
|
||||
private static function recent_events( int $limit ): array {
|
||||
return get_posts( [
|
||||
'post_type' => Events::EVENT, 'post_status' => 'publish', 'has_password' => false,
|
||||
'posts_per_page' => $limit, 'update_post_meta_cache' => false, 'update_post_term_cache' => false,
|
||||
] );
|
||||
}
|
||||
|
||||
public static function add_preview_box(): void {
|
||||
add_meta_box( 'eventlabs-loop-preview', __( 'Preview event', 'eventlabs-loop-builder' ), [ self::class, 'preview_box' ], self::POST_TYPE, 'side' );
|
||||
}
|
||||
|
||||
public static function preview_box( WP_Post $post ): void {
|
||||
$id = (int) get_post_meta( $post->ID, self::PREVIEW_META, true );
|
||||
wp_nonce_field( self::PREVIEW_ACTION, self::PREVIEW_NONCE );
|
||||
?>
|
||||
<p>
|
||||
<label for="eventlabs-loop-preview-event"><?php esc_html_e( 'Preview event ID', 'eventlabs-loop-builder' ); ?></label>
|
||||
<input class="widefat" id="eventlabs-loop-preview-event" name="eventlabs_loop_preview_event" type="text" inputmode="numeric"
|
||||
pattern="[0-9]+" list="eventlabs-loop-recent-events" aria-describedby="eventlabs-loop-preview-help" value="<?php echo $id ? esc_attr( (string) $id ) : ''; ?>">
|
||||
<datalist id="eventlabs-loop-recent-events">
|
||||
<?php foreach ( self::recent_events( 60 ) as $event ) : ?>
|
||||
<option value="<?php echo esc_attr( (string) $event->ID ); ?>"><?php echo esc_html( get_the_title( $event ) ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</datalist>
|
||||
</p>
|
||||
<p class="description" id="eventlabs-loop-preview-help"><?php esc_html_e( 'Choose a recent event or enter the ID of any published event. Leave blank to preview the next event automatically.', 'eventlabs-loop-builder' ); ?></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function save_preview( int $template_id ): void {
|
||||
$nonce = $_POST[ self::PREVIEW_NONCE ] ?? '';
|
||||
if ( ! is_string( $nonce ) || ! wp_verify_nonce( wp_unslash( $nonce ), self::PREVIEW_ACTION )
|
||||
|| ! current_user_can( 'edit_post', $template_id ) || wp_is_post_autosave( $template_id ) || wp_is_post_revision( $template_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$input = $_POST['eventlabs_loop_preview_event'] ?? '';
|
||||
$id = is_string( $input ) && ctype_digit( $input ) ? (int) $input : 0;
|
||||
if ( $id && self::is_preview_event( get_post( $id ) ) ) {
|
||||
update_post_meta( $template_id, self::PREVIEW_META, $id );
|
||||
} elseif ( '' === $input || '0' === $input ) {
|
||||
delete_post_meta( $template_id, self::PREVIEW_META );
|
||||
}
|
||||
}
|
||||
|
||||
public static function columns( array $columns ): array {
|
||||
return array_slice( $columns, 0, 2, true ) + [ 'ell_layout' => __( 'Layout', 'eventlabs-loop-builder' ) ] + $columns;
|
||||
}
|
||||
|
||||
public static function layout_column( string $column, int $id ): void {
|
||||
if ( 'ell_layout' === $column ) {
|
||||
$layout = (string) get_post_meta( $id, self::LAYOUT_META, true );
|
||||
echo esc_html( Presets::layouts()[ $layout ] ?? __( 'Any layout', 'eventlabs-loop-builder' ) );
|
||||
}
|
||||
}
|
||||
|
||||
public static function row_actions( array $actions, WP_Post $post ): array {
|
||||
if ( self::is_template( $post ) && current_user_can( self::CAPABILITY ) && current_user_can( 'edit_post', $post->ID ) && 'trash' !== $post->post_status ) {
|
||||
$url = add_query_arg( [ 'action' => 'eventlabs_loop_duplicate', 'template_id' => $post->ID ], admin_url( 'admin-post.php' ) );
|
||||
$actions['ell_duplicate'] = '<a href="' . esc_url( wp_nonce_url( $url, 'eventlabs_loop_duplicate_' . $post->ID ) ) . '">' . esc_html__( 'Duplicate', 'eventlabs-loop-builder' ) . '</a>';
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
public static function create_starter(): void {
|
||||
if ( ! current_user_can( self::CAPABILITY ) ) {
|
||||
wp_die( esc_html__( 'You cannot create a loop template.', 'eventlabs-loop-builder' ), '', [ 'response' => 403 ] );
|
||||
}
|
||||
check_admin_referer( self::STARTER_ACTION );
|
||||
$preset = isset( $_POST['preset'] ) && is_string( $_POST['preset'] ) ? sanitize_key( wp_unslash( $_POST['preset'] ) ) : '';
|
||||
$style = Presets::catalog()[ $preset ] ?? null;
|
||||
if ( $style ) {
|
||||
$title = self::preset_title( $style );
|
||||
$elements = Presets::elements( $preset );
|
||||
$meta = [ self::LAYOUT_META => $style['layout'] ];
|
||||
} elseif ( in_array( $preset, [ 'photo', 'compact' ], true ) ) {
|
||||
$title = 'compact' === $preset ? __( 'Compact event card', 'eventlabs-loop-builder' ) : __( 'Event photo card', 'eventlabs-loop-builder' );
|
||||
$elements = require __DIR__ . '/starter-layout.php';
|
||||
$meta = [];
|
||||
} else {
|
||||
wp_die( esc_html__( 'Choose a loop preset from the library.', 'eventlabs-loop-builder' ), '', [ 'response' => 400, 'back_link' => true ] );
|
||||
}
|
||||
self::create_draft( $title, wp_json_encode( $elements, JSON_THROW_ON_ERROR ), $meta );
|
||||
}
|
||||
|
||||
public static function duplicate(): void {
|
||||
$id = isset( $_GET['template_id'] ) && is_string( $_GET['template_id'] ) ? absint( $_GET['template_id'] ) : 0;
|
||||
$post = $id ? get_post( $id ) : null;
|
||||
if ( ! self::is_template( $post ) || 'trash' === $post->post_status || ! current_user_can( self::CAPABILITY ) || ! current_user_can( 'edit_post', $id ) ) {
|
||||
wp_die( esc_html__( 'You cannot duplicate this loop template.', 'eventlabs-loop-builder' ), '', [ 'response' => 403 ] );
|
||||
}
|
||||
check_admin_referer( 'eventlabs_loop_duplicate_' . $id );
|
||||
$meta = array_intersect_key( get_post_meta( $id ), array_flip( [ self::LAYOUT_META, self::PREVIEW_META, '_elementor_page_settings', '_wp_page_template' ] ) );
|
||||
/* translators: %s: loop template title. */
|
||||
$title = sprintf( __( '%s (copy)', 'eventlabs-loop-builder' ), $post->post_title );
|
||||
$settings = array_map( static fn( array $values ) => maybe_unserialize( $values[0] ), $meta );
|
||||
self::create_draft( $title, (string) get_post_meta( $id, Document::ELEMENTOR_DATA_META_KEY, true ) ?: '[]', $settings );
|
||||
}
|
||||
|
||||
private static function preset_title( array $style ): string {
|
||||
/* translators: 1: style family, 2: layout, 3: preset name. */
|
||||
return sprintf( __( '%1$s %2$s · %3$s', 'eventlabs-loop-builder' ), Presets::families()[ $style['family'] ], Presets::layouts()[ $style['layout'] ], $style['title'] );
|
||||
}
|
||||
|
||||
private static function create_draft( string $title, string $elements, array $meta ): void {
|
||||
$id = wp_insert_post( [
|
||||
'post_type' => self::POST_TYPE,
|
||||
'post_status' => 'draft',
|
||||
'post_title' => wp_slash( $title ),
|
||||
'meta_input' => wp_slash( [ Document::ELEMENTOR_DATA_META_KEY => $elements ] + $meta ),
|
||||
], true );
|
||||
if ( is_wp_error( $id ) ) {
|
||||
wp_die( esc_html( $id->get_error_message() ), '', [ 'response' => 500, 'back_link' => true ] );
|
||||
}
|
||||
|
||||
$document = Elementor::instance()->documents->get( $id );
|
||||
if ( ! $document || get_post_meta( $id, Document::ELEMENTOR_DATA_META_KEY, true ) !== $elements ) {
|
||||
wp_die( esc_html__( 'WordPress could not save the loop layout.', 'eventlabs-loop-builder' ), '', [ 'response' => 500, 'back_link' => true ] );
|
||||
}
|
||||
$document->set_is_built_with_elementor( true );
|
||||
wp_safe_redirect( $document->get_edit_url() );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function published_layout( int $id ): ?WP_Post {
|
||||
$post = $id ? get_post( $id ) : null;
|
||||
if ( ! self::is_template( $post ) || 'publish' !== $post->post_status || '' !== $post->post_password ) {
|
||||
return null;
|
||||
}
|
||||
$document = Elementor::instance()->documents->get( $id );
|
||||
return $document && $document->is_built_with_elementor() ? $post : null;
|
||||
}
|
||||
|
||||
public static function options(): array {
|
||||
$templates = get_posts( [
|
||||
'post_type' => self::POST_TYPE, 'post_status' => 'publish', 'has_password' => false,
|
||||
'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'update_post_term_cache' => false,
|
||||
] );
|
||||
$options = [ '' => __( 'Built-in event card', 'eventlabs-loop-builder' ) ];
|
||||
foreach ( Presets::catalog() as $slug => $style ) {
|
||||
$options[ $slug ] = self::preset_title( $style );
|
||||
}
|
||||
foreach ( $templates as $template ) {
|
||||
if ( self::published_layout( $template->ID ) ) {
|
||||
$options[ $template->ID ] = get_the_title( $template ) ?: __( '(Untitled template)', 'eventlabs-loop-builder' );
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public static function render( WP_Post $template, Card $card ): string {
|
||||
$previous = self::$card;
|
||||
self::$card = $card;
|
||||
try {
|
||||
// Render only the saved layout. The card context supplies the event and occurrence to the dynamic fields.
|
||||
return Elementor::instance()->frontend->get_builder_content_for_display( $template->ID );
|
||||
} finally {
|
||||
self::$card = $previous;
|
||||
}
|
||||
}
|
||||
}
|
||||
338
addons/eventlabs-loop-builder/includes/class-widgets.php
Normal file
338
addons/eventlabs-loop-builder/includes/class-widgets.php
Normal file
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
|
||||
namespace EventLabs\LoopBuilder;
|
||||
|
||||
use BurnEvents\Events;
|
||||
use BurnEvents\Map_View;
|
||||
use Elementor\Controls_Manager;
|
||||
use Elementor\Group_Control_Typography;
|
||||
use Elementor\Plugin as Elementor;
|
||||
use Elementor\Widget_Base;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
abstract class Loop_Builder_Widget extends Widget_Base {
|
||||
public function get_categories(): array {
|
||||
return [ 'burn-events' ];
|
||||
}
|
||||
|
||||
public function get_style_depends(): array {
|
||||
return [ ASSET . '-presets' ];
|
||||
}
|
||||
|
||||
public function get_script_depends(): array {
|
||||
return [ ASSET ];
|
||||
}
|
||||
|
||||
protected function is_dynamic_content(): bool {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final class Loop_Widget extends Loop_Builder_Widget {
|
||||
public function get_name(): string {
|
||||
return 'eventlabs-event-loop';
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return __( 'Event Loop', 'eventlabs-loop-builder' );
|
||||
}
|
||||
|
||||
public function get_icon(): string {
|
||||
return 'eicon-posts-grid';
|
||||
}
|
||||
|
||||
public function get_keywords(): array {
|
||||
return [ 'eventlabs', 'calendar', 'events', 'loop', 'card' ];
|
||||
}
|
||||
|
||||
protected function register_controls(): void {
|
||||
$this->start_controls_section( 'display', [ 'label' => __( 'Layout', 'eventlabs-loop-builder' ) ] );
|
||||
$this->add_control( 'template_id', [
|
||||
'label' => __( 'Loop template', 'eventlabs-loop-builder' ),
|
||||
'type' => Controls_Manager::SELECT2,
|
||||
'options' => Templates::options(),
|
||||
'description' => __( 'Choose a preset or a saved template. Browse editable copies under Events → Loop Presets.', 'eventlabs-loop-builder' ),
|
||||
'default' => '',
|
||||
] );
|
||||
$this->add_control( 'layout', [
|
||||
'label' => __( 'Display as', 'eventlabs-loop-builder' ),
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => [ 'auto' => __( 'Use template layout', 'eventlabs-loop-builder' ) ] + Presets::layouts(),
|
||||
'default' => 'auto',
|
||||
] );
|
||||
$this->add_responsive_control( 'columns', [
|
||||
'label' => __( 'Columns', 'eventlabs-loop-builder' ),
|
||||
'type' => Controls_Manager::NUMBER,
|
||||
'min' => 1, 'max' => 6, 'step' => 1,
|
||||
'default' => 3, 'tablet_default' => 2, 'mobile_default' => 1,
|
||||
'condition' => [ 'layout!' => 'list' ],
|
||||
'selectors' => [ '{{WRAPPER}} > .elementor-widget-container > .ell-loop, {{WRAPPER}} > .ell-loop' => '--ell-columns: {{VALUE}};' ],
|
||||
] );
|
||||
$this->add_responsive_control( 'gap', [
|
||||
'label' => __( 'Card spacing', 'eventlabs-loop-builder' ),
|
||||
'type' => Controls_Manager::SLIDER,
|
||||
'size_units' => [ 'px', 'rem' ],
|
||||
'range' => [ 'px' => [ 'min' => 0, 'max' => 64 ], 'rem' => [ 'min' => 0, 'max' => 4, 'step' => .125 ] ],
|
||||
'selectors' => [ '{{WRAPPER}} > .elementor-widget-container > .ell-loop, {{WRAPPER}} > .ell-loop' => '--ell-gap: {{SIZE}}{{UNIT}};' ],
|
||||
] );
|
||||
$this->add_control( 'equal_height', [ 'label' => __( 'Equal-height cards', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes' ] );
|
||||
$this->add_control( 'month_headers', [ 'label' => __( 'Group list by month', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SWITCHER, 'condition' => [ 'layout' => [ 'auto', 'list' ] ] ] );
|
||||
$this->end_controls_section();
|
||||
|
||||
$this->start_controls_section( 'query', [ 'label' => __( 'Event query', 'eventlabs-loop-builder' ) ] );
|
||||
Query::controls( $this );
|
||||
$this->end_controls_section();
|
||||
$this->start_controls_section( 'filter_bar', [ 'label' => __( 'Filter bar', 'eventlabs-loop-builder' ) ] );
|
||||
Query::filter_controls( $this );
|
||||
$this->end_controls_section();
|
||||
|
||||
$this->start_controls_section( 'page_controls', [ 'label' => __( 'Pagination', 'eventlabs-loop-builder' ) ] );
|
||||
$this->add_control( 'pagination_mode', [
|
||||
'label' => __( 'Pagination', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => [ '' => __( 'Default (page links)', 'eventlabs-loop-builder' ), 'links' => __( 'Page links', 'eventlabs-loop-builder' ), 'more' => __( 'Load more', 'eventlabs-loop-builder' ), 'none' => __( 'None', 'eventlabs-loop-builder' ) ],
|
||||
'default' => '',
|
||||
] );
|
||||
$this->add_control( 'more_label', [ 'label' => __( 'Load more label', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'Load more events', 'eventlabs-loop-builder' ), 'condition' => [ 'pagination_mode' => 'more' ] ] );
|
||||
$this->end_controls_section();
|
||||
|
||||
$this->start_controls_section( 'carousel_options', [ 'label' => __( 'Carousel', 'eventlabs-loop-builder' ), 'condition' => [ 'layout' => [ 'auto', 'carousel' ] ] ] );
|
||||
$this->add_control( 'carousel_arrows', [ 'label' => __( 'Show arrows', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes' ] );
|
||||
$this->add_control( 'carousel_indicator', [
|
||||
'label' => __( 'Slide indicator', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => [ '' => __( 'None', 'eventlabs-loop-builder' ), 'dots' => __( 'Dots', 'eventlabs-loop-builder' ), 'fraction' => __( 'Fraction', 'eventlabs-loop-builder' ), 'progress' => __( 'Progress bar', 'eventlabs-loop-builder' ) ],
|
||||
'default' => 'dots',
|
||||
] );
|
||||
$this->add_control( 'carousel_autoplay', [ 'label' => __( 'Autoplay', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SWITCHER ] );
|
||||
$this->add_control( 'carousel_interval', [ 'label' => __( 'Seconds between slides', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::NUMBER, 'min' => 2, 'max' => 30, 'default' => 5, 'condition' => [ 'carousel_autoplay' => 'yes' ] ] );
|
||||
$this->add_control( 'carousel_step', [ 'label' => __( 'Slides per move', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::NUMBER, 'min' => 1, 'max' => 6, 'default' => 1 ] );
|
||||
$this->add_control( 'carousel_loop', [ 'label' => __( 'Wrap at the ends', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SWITCHER ] );
|
||||
$this->add_control( 'carousel_effect', [
|
||||
'label' => __( 'Slide effect', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => [ 'slide' => __( 'Slide', 'eventlabs-loop-builder' ), 'focus' => __( 'Focus active card', 'eventlabs-loop-builder' ) ], 'default' => 'slide',
|
||||
] );
|
||||
$this->end_controls_section();
|
||||
|
||||
$this->start_controls_section( 'loop_style', [ 'label' => __( 'Event Loop', 'eventlabs-loop-builder' ), 'tab' => Controls_Manager::TAB_STYLE ] );
|
||||
foreach ( [ 'accent' => __( 'Accent color', 'eventlabs-loop-builder' ), 'ink' => __( 'Text color', 'eventlabs-loop-builder' ), 'line' => __( 'Control borders', 'eventlabs-loop-builder' ) ] as $key => $label ) {
|
||||
$this->add_control( 'loop_' . $key, [ 'label' => $label, 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ell-loop' => '--ell-' . $key . ': {{VALUE}};' ] ] );
|
||||
}
|
||||
$this->end_controls_section();
|
||||
}
|
||||
|
||||
protected function render(): void {
|
||||
$editing = Templates::is_editing();
|
||||
if ( Templates::is_rendering_card() || Templates::current_template() ) {
|
||||
if ( $editing && ! Templates::is_rendering_card() ) {
|
||||
echo '<p class="ell-empty">' . esc_html__( 'Add the Event Loop widget to a page and use Loop Event Field to design a card.', 'eventlabs-loop-builder' ) . '</p>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = $this->get_settings_for_display();
|
||||
$template_key = (string) ( $settings['template_id'] ?? '' );
|
||||
$style = Presets::catalog()[ $template_key ] ?? null;
|
||||
$template = ctype_digit( $template_key ) ? Templates::published_layout( (int) $template_key ) : null;
|
||||
$template_layout = $style['layout'] ?? ( $template ? get_post_meta( $template->ID, Templates::LAYOUT_META, true ) : '' );
|
||||
$layout = $settings['layout'] ?? 'auto';
|
||||
if ( ! isset( Presets::layouts()[ $layout ] ) ) {
|
||||
$layout = isset( Presets::layouts()[ $template_layout ] ) ? $template_layout : 'grid';
|
||||
}
|
||||
$document = Elementor::instance()->documents->get_current();
|
||||
$document_id = $document ? $document->get_main_id() : get_queried_object_id();
|
||||
$instance = absint( $document_id ) . '-' . sanitize_key( $this->get_id() );
|
||||
$id = 'eventlabs-loop-' . $instance;
|
||||
$result = Query::results( $settings, $instance, $editing );
|
||||
$cards = self::cards( $result['rows'] );
|
||||
$group = 'list' === $layout && 'yes' === ( $settings['month_headers'] ?? '' );
|
||||
$more = 'more' === Query::pagination( $settings );
|
||||
$carousel = 'carousel' === $layout;
|
||||
$style_class = 'yes' === ( $settings['equal_height'] ?? 'yes' ) ? '' : ' ell-natural-height';
|
||||
$style_class .= $carousel && 'focus' === ( $settings['carousel_effect'] ?? '' ) ? ' ell-focus-effect' : '';
|
||||
?>
|
||||
<section class="ell-loop ell-layout-<?php echo esc_attr( $layout . $style_class ); ?>" id="<?php echo esc_attr( $id ); ?>" aria-label="<?php esc_attr_e( 'Events', 'eventlabs-loop-builder' ); ?>"<?php if ( $group ) { echo ' data-ell-grouped'; } ?>>
|
||||
<?php echo $result['filters']; // Escaped by the query renderer. ?>
|
||||
<?php if ( $editing && $template_key && ! $template && ! $style ) : ?>
|
||||
<p class="ell-empty"><?php esc_html_e( 'The selected template is unavailable. Choose a published loop template.', 'eventlabs-loop-builder' ); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if ( ! $cards ) : ?>
|
||||
<p class="ell-empty"><?php echo esc_html( $editing && $result['error'] ? $result['error'] : ( $settings['empty_message'] ?? __( 'No events match these filters.', 'eventlabs-loop-builder' ) ) ); ?></p>
|
||||
<?php else : ?>
|
||||
<?php if ( $carousel ) : ?>
|
||||
<?php self::carousel_controls( $settings, $id, $editing ); ?>
|
||||
<?php endif; ?>
|
||||
<div class="ell-items" id="<?php echo esc_attr( $id . '-items' ); ?>"<?php if ( ! $group ) { echo ' role="list"'; } ?><?php if ( 'carousel' === $layout ) { echo ' tabindex="0"'; } ?>>
|
||||
<?php $last_month = ''; ?>
|
||||
<?php foreach ( $cards as $card ) : ?>
|
||||
<?php if ( $group && ( $month = $card->month() ) && $last_month !== $month->format( 'Y-m' ) ) : ?>
|
||||
<?php $last_month = $month->format( 'Y-m' ); ?>
|
||||
<h2 class="ell-month" data-ell-month="<?php echo esc_attr( $last_month ); ?>"><?php echo esc_html( wp_date( 'F Y', $month->getTimestamp(), $month->getTimezone() ) ); ?></h2>
|
||||
<?php endif; ?>
|
||||
<div class="ell-item"<?php if ( ! $group ) { echo ' role="listitem"'; } ?>>
|
||||
<?php
|
||||
$html = $template ? Templates::render( $template, $card ) : ( $style ? Presets::render( $template_key, $card ) : '' );
|
||||
echo trim( $html ) ? $html : $card->built_in(); // Elementor renders trusted, published template content.
|
||||
?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ( $result['previous'] || $result['next'] ) : ?>
|
||||
<nav class="ell-pagination" aria-label="<?php esc_attr_e( 'Event pages', 'eventlabs-loop-builder' ); ?>"<?php if ( $more ) { echo ' data-ell-more'; } ?>>
|
||||
<?php if ( $result['previous'] ) : ?>
|
||||
<a class="ell-nav-button" rel="prev" href="<?php echo esc_url( $result['previous'] ); ?>"><?php esc_html_e( 'Previous events', 'eventlabs-loop-builder' ); ?></a>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
/* translators: %s: event page number */
|
||||
$page_label = sprintf( __( 'Page %s', 'eventlabs-loop-builder' ), number_format_i18n( $result['page'] ) );
|
||||
?>
|
||||
<span class="ell-page" aria-current="page"><?php echo esc_html( $page_label ); ?></span>
|
||||
<?php if ( $result['next'] ) : ?>
|
||||
<a class="ell-nav-button" rel="next" href="<?php echo esc_url( $result['next'] ); ?>"><?php echo esc_html( $more ? ( ( $settings['more_label'] ?? '' ) ?: __( 'Load more events', 'eventlabs-loop-builder' ) ) : __( 'Next events', 'eventlabs-loop-builder' ) ); ?></a>
|
||||
<?php endif; ?>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
<?php if ( $more ) : ?>
|
||||
<p class="ell-more-status" tabindex="-1" role="status" data-ell-more-status data-loaded="<?php esc_attr_e( 'More events loaded.', 'eventlabs-loop-builder' ); ?>" data-done="<?php esc_attr_e( 'All events loaded.', 'eventlabs-loop-builder' ); ?>" data-error="<?php esc_attr_e( 'Unable to load more events. Select the link again to open the next page.', 'eventlabs-loop-builder' ); ?>"></p>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function carousel_controls( array $settings, string $id, bool $editing ): void {
|
||||
$arrows = 'yes' === ( $settings['carousel_arrows'] ?? 'yes' );
|
||||
$indicator = $settings['carousel_indicator'] ?? 'dots';
|
||||
$autoplay = ! $editing && 'yes' === ( $settings['carousel_autoplay'] ?? '' ) ? max( 2, min( 30, absint( $settings['carousel_interval'] ?? 5 ) ) ) : 0;
|
||||
$step = max( 1, min( 6, absint( $settings['carousel_step'] ?? 1 ) ) );
|
||||
?>
|
||||
<div class="ell-carousel-controls" data-ell-step="<?php echo (int) $step; ?>" data-ell-autoplay="<?php echo (int) $autoplay; ?>" data-ell-wrap="<?php echo 'yes' === ( $settings['carousel_loop'] ?? '' ) ? '1' : '0'; ?>" hidden>
|
||||
<?php if ( $indicator ) : ?>
|
||||
<div class="ell-carousel-indicator" data-ell-indicator="<?php echo esc_attr( $indicator ); ?>" data-slide-label="<?php esc_attr_e( 'Go to slide %d', 'eventlabs-loop-builder' ); ?>" aria-label="<?php esc_attr_e( 'Carousel position', 'eventlabs-loop-builder' ); ?>"></div>
|
||||
<?php endif; ?>
|
||||
<?php if ( $autoplay ) : ?>
|
||||
<button class="ell-nav-button ell-carousel-toggle" type="button" data-ell-play data-pause="<?php esc_attr_e( 'Pause', 'eventlabs-loop-builder' ); ?>" data-play="<?php esc_attr_e( 'Play', 'eventlabs-loop-builder' ); ?>"><?php esc_html_e( 'Pause', 'eventlabs-loop-builder' ); ?></button>
|
||||
<?php endif; ?>
|
||||
<?php if ( $arrows ) : ?>
|
||||
<button class="ell-nav-button" type="button" data-ell-direction="-1" aria-label="<?php esc_attr_e( 'Scroll to previous cards', 'eventlabs-loop-builder' ); ?>" aria-controls="<?php echo esc_attr( $id . '-items' ); ?>"><span aria-hidden="true">←</span></button>
|
||||
<button class="ell-nav-button" type="button" data-ell-direction="1" aria-label="<?php esc_attr_e( 'Scroll to next cards', 'eventlabs-loop-builder' ); ?>" aria-controls="<?php echo esc_attr( $id . '-items' ); ?>"><span aria-hidden="true">→</span></button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function cards( array $rows ): array {
|
||||
if ( ! $rows ) {
|
||||
return [];
|
||||
}
|
||||
$ids = array_unique( array_map( 'intval', array_column( $rows, 'event_id' ) ) );
|
||||
$posts = get_posts( [
|
||||
'post_type' => Events::EVENT, 'post_status' => 'publish', 'has_password' => false,
|
||||
'post__in' => $ids, 'posts_per_page' => count( $ids ),
|
||||
] );
|
||||
$events = array_column( $posts, null, 'ID' );
|
||||
$cards = [];
|
||||
foreach ( $rows as $row ) {
|
||||
$event = $events[ (int) $row['event_id'] ] ?? null;
|
||||
if ( $event ) {
|
||||
$cards[] = new Card( $event, $row );
|
||||
}
|
||||
}
|
||||
return $cards;
|
||||
}
|
||||
}
|
||||
|
||||
final class Field_Widget extends Loop_Builder_Widget {
|
||||
public function get_style_depends(): array {
|
||||
$styles = parent::get_style_depends();
|
||||
return 'map' === $this->get_settings( 'field' ) ? [ ...$styles, Map_View::STYLE ] : $styles;
|
||||
}
|
||||
|
||||
public function get_script_depends(): array {
|
||||
$scripts = parent::get_script_depends();
|
||||
return 'map' === $this->get_settings( 'field' ) ? [ ...$scripts, Map_View::SCRIPT ] : $scripts;
|
||||
}
|
||||
|
||||
public function get_name(): string {
|
||||
return 'eventlabs-loop-field';
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return __( 'Loop Event Field', 'eventlabs-loop-builder' );
|
||||
}
|
||||
|
||||
public function get_icon(): string {
|
||||
return 'eicon-dynamic-tags';
|
||||
}
|
||||
|
||||
public function get_keywords(): array {
|
||||
return [ 'eventlabs', 'event', 'loop', 'dynamic', 'field' ];
|
||||
}
|
||||
|
||||
protected function register_controls(): void {
|
||||
$this->start_controls_section( 'field_settings', [ 'label' => __( 'Event field', 'eventlabs-loop-builder' ) ] );
|
||||
$this->add_control( 'field', [
|
||||
'label' => __( 'Field', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => Card::fields(), 'default' => 'title',
|
||||
] );
|
||||
$this->add_control( 'heading_tag', [
|
||||
'label' => __( 'Heading tag', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => [ 'h2' => 'H2', 'h3' => 'H3', 'h4' => 'H4', 'h5' => 'H5', 'h6' => 'H6', 'p' => 'P' ],
|
||||
'default' => 'h3', 'condition' => [ 'field' => 'title' ],
|
||||
] );
|
||||
$this->add_control( 'link_title', [
|
||||
'label' => __( 'Link the title to the event', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SWITCHER,
|
||||
'default' => 'yes', 'condition' => [ 'field' => 'title' ],
|
||||
] );
|
||||
$this->add_control( 'image_size', [
|
||||
'label' => __( 'Image size', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => [
|
||||
'medium' => __( 'Medium', 'eventlabs-loop-builder' ), 'medium_large' => __( 'Medium large', 'eventlabs-loop-builder' ),
|
||||
'large' => __( 'Large', 'eventlabs-loop-builder' ), 'full' => __( 'Full size', 'eventlabs-loop-builder' ),
|
||||
],
|
||||
'default' => 'large', 'condition' => [ 'field' => 'image' ],
|
||||
] );
|
||||
$this->add_control( 'show_placeholder', [
|
||||
'label' => __( 'Show date tile when there is no image', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SWITCHER,
|
||||
'condition' => [ 'field' => 'image' ],
|
||||
] );
|
||||
$this->add_control( 'link_image', [
|
||||
'label' => __( 'Link the image to the event', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SWITCHER, 'condition' => [ 'field' => 'image' ],
|
||||
] );
|
||||
$this->add_control( 'excerpt_words', [
|
||||
'label' => __( 'Excerpt word limit', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::NUMBER, 'min' => 1, 'max' => 100, 'default' => 27, 'condition' => [ 'field' => 'excerpt' ],
|
||||
] );
|
||||
$this->add_control( 'link_label', [
|
||||
'label' => __( 'Link text', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::TEXT,
|
||||
'condition' => [ 'field' => [ 'link', 'website' ] ],
|
||||
] );
|
||||
$this->add_control( 'custom_key', [
|
||||
'label' => __( 'Custom field', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::SELECT,
|
||||
'options' => Card::custom_fields(), 'condition' => [ 'field' => 'custom' ],
|
||||
] );
|
||||
$this->end_controls_section();
|
||||
|
||||
$this->start_controls_section( 'field_style', [ 'label' => __( 'Field style', 'eventlabs-loop-builder' ), 'tab' => Controls_Manager::TAB_STYLE ] );
|
||||
$this->add_group_control( Group_Control_Typography::get_type(), [
|
||||
'name' => 'typography',
|
||||
'selector' => '{{WRAPPER}} .ell-field, {{WRAPPER}} .ell-field a',
|
||||
] );
|
||||
$this->add_control( 'text_color', [
|
||||
'label' => __( 'Text color', 'eventlabs-loop-builder' ), 'type' => Controls_Manager::COLOR,
|
||||
'selectors' => [ '{{WRAPPER}} .ell-field, {{WRAPPER}} .ell-field a' => 'color: {{VALUE}};' ],
|
||||
] );
|
||||
$this->end_controls_section();
|
||||
}
|
||||
|
||||
protected function render(): void {
|
||||
$card = Templates::active_card();
|
||||
$settings = $this->get_settings_for_display();
|
||||
$field = (string) ( $settings['field'] ?? 'title' );
|
||||
$content = $card ? $card->field( $field, $settings ) : '';
|
||||
if ( $content ) {
|
||||
echo $content; // Card escaped the field value and attributes.
|
||||
} elseif ( Templates::is_editing() ) {
|
||||
$label = Card::fields()[ $field ] ?? __( 'Event field', 'eventlabs-loop-builder' );
|
||||
echo '<p class="ell-field-placeholder">' . esc_html( $label ) . '</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
35
addons/eventlabs-loop-builder/includes/starter-layout.php
Normal file
35
addons/eventlabs-loop-builder/includes/starter-layout.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$field = static function ( string $key, array $settings = [] ): array {
|
||||
return [
|
||||
'id' => Elementor\Utils::generate_random_string(), 'elType' => 'widget', 'widgetType' => 'eventlabs-loop-field',
|
||||
'settings' => [ 'field' => $key ] + $settings, 'elements' => [],
|
||||
];
|
||||
};
|
||||
$container = static function ( string $classes, array $children, bool $inner = true ): array {
|
||||
return [
|
||||
'id' => Elementor\Utils::generate_random_string(), 'elType' => 'container', 'isInner' => $inner,
|
||||
'settings' => [ 'content_width' => 'full', 'css_classes' => $classes ], 'elements' => $children,
|
||||
];
|
||||
};
|
||||
|
||||
$body = $container( 'ell-starter-body', [
|
||||
$field( 'categories' ),
|
||||
$field( 'schedule' ),
|
||||
$field( 'title' ),
|
||||
$field( 'venue' ),
|
||||
$field( 'excerpt' ),
|
||||
$container( 'ell-starter-meta', [ $field( 'cost' ), $field( 'status' ) ] ),
|
||||
$field( 'link' ),
|
||||
] );
|
||||
|
||||
return [
|
||||
'compact' === $preset
|
||||
? $container( 'ell-starter ell-starter-compact', [ $body ], false )
|
||||
: $container( 'ell-starter ell-starter-photo', [
|
||||
$container( 'ell-starter-media', [ $field( 'image', [ 'show_placeholder' => 'yes' ] ) ] ),
|
||||
$body,
|
||||
], false ),
|
||||
];
|
||||
@@ -317,7 +317,13 @@
|
||||
padding: clamp(30px, 5vw, 60px);
|
||||
background: radial-gradient(ellipse at 15% 100%, #323b80, transparent 75%);
|
||||
}
|
||||
.be-single-layout .be-event-title { color: #fff; font-size: clamp(2.2rem, 5vw, 4.05rem); line-height: 1.02; text-wrap: pretty; }
|
||||
.be-single-layout .be-event-title {
|
||||
color: #fff;
|
||||
font: 700 clamp(2.2rem, 5vw, 4.05rem)/1.06 Inter, system-ui, sans-serif;
|
||||
letter-spacing: -.045em;
|
||||
overflow-wrap: anywhere;
|
||||
text-wrap: pretty;
|
||||
}
|
||||
.be-single-layout .be-single-date { color: #dce4ff; font-size: clamp(.92rem, 1.7vw, 1.06rem); line-height: 1.5; }
|
||||
.be-single-layout .be-layout-title .be-status { margin: 0; border-radius: 999px; padding: .3em .8em; background: #dedfff; color: #272d65; }
|
||||
.be-single-layout .be-layout-photo.e-con { position: relative; min-height: clamp(265px, 33vw, 390px); padding: 0; }
|
||||
|
||||
@@ -5,14 +5,44 @@
|
||||
const endpoint = form.getAttribute('action');
|
||||
|
||||
const {__, sprintf} = wp.i18n;
|
||||
const button = form.querySelector('button[type="submit"]');
|
||||
const buttons = Array.from(form.querySelectorAll('[data-be-operation]'));
|
||||
const template = form.querySelector('[name="template_id"]');
|
||||
const status = form.querySelector('[data-be-migrate-status]');
|
||||
const errors = form.querySelector('[data-be-migrate-errors]');
|
||||
const retryableStatuses = new Set([408, 429, 502, 503, 504]);
|
||||
let copied = 0;
|
||||
const messages = {
|
||||
copy: {
|
||||
count: 'copied',
|
||||
starting: __('Copying events…', 'burn-events'),
|
||||
progress: __('Copying events. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events'),
|
||||
finished: __('Migration finished. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events'),
|
||||
paused: __('Migration paused. %1$d copied, %2$d already copied. %3$s', 'burn-events'),
|
||||
},
|
||||
apply: {
|
||||
count: 'applied',
|
||||
starting: __('Applying the template…', 'burn-events'),
|
||||
progress: __('Applying the template. %1$d applied, %2$d already assigned, %3$d need review.', 'burn-events'),
|
||||
finished: __('Template assignment finished. %1$d applied, %2$d already assigned, %3$d need review.', 'burn-events'),
|
||||
paused: __('Template assignment paused. %1$d applied, %2$d already assigned. %3$s', 'burn-events'),
|
||||
},
|
||||
};
|
||||
let operation = '';
|
||||
let templateId = '0';
|
||||
let hasCopies = form.dataset.hasCopies === '1';
|
||||
let processed = 0;
|
||||
let skipped = 0;
|
||||
let after = 0;
|
||||
button.disabled = false;
|
||||
|
||||
function updateControls(busy) {
|
||||
if (template) template.disabled = busy;
|
||||
for (const button of buttons) {
|
||||
const canApply = hasCopies && template && template.value !== '0';
|
||||
button.disabled = busy || (button.value === 'apply' && !canApply);
|
||||
}
|
||||
}
|
||||
|
||||
template?.addEventListener('change', () => updateControls(false));
|
||||
updateControls(false);
|
||||
|
||||
async function requestBatch(body) {
|
||||
for (let attempt = 0; ; attempt++) {
|
||||
@@ -29,16 +59,16 @@
|
||||
if (requestedDelay > 10000) return response;
|
||||
if (requestedDelay > delay) delay = requestedDelay;
|
||||
}
|
||||
status.textContent = __('Waiting to retry the last migration batch…', 'burn-events');
|
||||
status.textContent = __('Waiting to retry the last batch…', 'burn-events');
|
||||
await new Promise(resolve => setTimeout(resolve, delay));
|
||||
}
|
||||
}
|
||||
|
||||
async function readBatch(response) {
|
||||
async function readBatch(response, count) {
|
||||
const result = await response.json().catch(() => null);
|
||||
if (response.ok && result?.success === true) {
|
||||
const batch = result.data;
|
||||
const counts = [batch?.copied, batch?.skipped, batch?.next];
|
||||
const counts = [batch?.[count], batch?.skipped, batch?.next];
|
||||
if (counts.every(value => Number.isSafeInteger(value) && value >= 0)
|
||||
&& (batch.next === 0 || batch.next > after) && Array.isArray(batch.errors)) return batch;
|
||||
}
|
||||
@@ -55,39 +85,41 @@
|
||||
|
||||
form.addEventListener('submit', async event => {
|
||||
event.preventDefault();
|
||||
if (button.disabled) return;
|
||||
button.disabled = true;
|
||||
if (after === 0) {
|
||||
copied = 0;
|
||||
const button = event.submitter ?? buttons.find(control => !control.disabled);
|
||||
if (!button || button.disabled) return;
|
||||
const selectedTemplate = template?.value ?? '0';
|
||||
if (after === 0 || operation !== button.value || templateId !== selectedTemplate) {
|
||||
after = 0;
|
||||
processed = 0;
|
||||
skipped = 0;
|
||||
errors.replaceChildren();
|
||||
}
|
||||
status.textContent = __('Copying events…', 'burn-events');
|
||||
operation = button.value;
|
||||
templateId = selectedTemplate;
|
||||
const labels = messages[operation];
|
||||
const body = new URLSearchParams(new FormData(form));
|
||||
body.set('operation', operation);
|
||||
updateControls(true);
|
||||
status.textContent = labels.starting;
|
||||
try {
|
||||
do {
|
||||
body.set('after', String(after));
|
||||
const batch = await readBatch(await requestBatch(body));
|
||||
copied += batch.copied;
|
||||
const batch = await readBatch(await requestBatch(body), labels.count);
|
||||
processed += batch[labels.count];
|
||||
skipped += batch.skipped;
|
||||
if (operation === 'copy' && (processed || skipped)) hasCopies = true;
|
||||
for (const error of batch.errors) {
|
||||
const item = document.createElement('li');
|
||||
item.textContent = error;
|
||||
errors.append(item);
|
||||
}
|
||||
after = batch.next;
|
||||
status.textContent = sprintf(
|
||||
after ? __('Copying events. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events')
|
||||
: __('Migration finished. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events'),
|
||||
copied, skipped, errors.childElementCount
|
||||
);
|
||||
status.textContent = sprintf(after ? labels.progress : labels.finished, processed, skipped, errors.childElementCount);
|
||||
} while (after);
|
||||
} catch (error) {
|
||||
status.textContent = sprintf(
|
||||
__('Migration paused. %1$d copied, %2$d already copied. %3$s', 'burn-events'), copied, skipped, error.message
|
||||
);
|
||||
status.textContent = sprintf(labels.paused, processed, skipped, error.message);
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
updateControls(false);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: eventLabs
|
||||
* Plugin URI: https://git.labs.casa/josh/eventLabs
|
||||
* Description: Calendars, recurring events, community submissions, and a Single Event template builder for Elementor.
|
||||
* Version: 0.5.6
|
||||
* Version: 0.5.8
|
||||
* Requires at least: 6.9
|
||||
* Requires PHP: 8.1
|
||||
* Author: hostLabs
|
||||
@@ -16,7 +16,7 @@ declare(strict_types=1);
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
define( 'BURN_EVENTS_FILE', __FILE__ );
|
||||
define( 'BURN_EVENTS_VERSION', '0.5.6' );
|
||||
define( 'BURN_EVENTS_VERSION', '0.5.8' );
|
||||
|
||||
foreach ( [ 'schedule', 'maps', 'events', 'admin', 'map-view', 'calendar-grid', 'calendar', 'community', 'transfer', 'single-event-templates', 'api', 'burnworks', 'clubs', 'legacy-migration', 'updates', 'platform' ] as $module ) {
|
||||
require_once __DIR__ . '/includes/class-' . $module . '.php';
|
||||
|
||||
35
docs/MIGRATION.md
Normal file
35
docs/MIGRATION.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Migrate from The Events Calendar to eventLabs
|
||||
|
||||
Use this guide to copy events on a WordPress site that contains The Events Calendar data. The migration uses the records already in that site's database. To test before switching your live calendar, start with a staging clone that includes the database and media library.
|
||||
|
||||
## 1. Install eventLabs on the clone
|
||||
|
||||
1. Sign in as a WordPress administrator.
|
||||
2. Install and activate eventLabs through **Plugins → Add Plugin → Upload Plugin**. Existing eventLabs installations can update through **Dashboard → Updates**. The template controls in this guide require eventLabs 0.5.7 or later. [Download eventLabs](https://git.labs.casa/josh/eventLabs/releases/latest)
|
||||
3. Open **Events → Import and Export** in the eventLabs menu. Under **Migrate from The Events Calendar**, check the count of source events. The importer can read those records while The Events Calendar is inactive.
|
||||
|
||||
## 2. Prepare a single event template (optional)
|
||||
|
||||
1. Activate Elementor. Elementor Free supports the eventLabs template builder.
|
||||
2. Go to **Events → Single Event Templates → Create starter template**. The starter layout uses eventLabs widgets for the title, schedule, featured image, description, venue, and other event details. Edit the layout in Elementor and publish it.
|
||||
3. Return to **Events → Import and Export**. Under **Single event template**, select the published layout to assign it to new copies. **Inherit site default** uses the default from **Single Event Templates** or the built-in layout when no default is set.
|
||||
|
||||
## 3. Copy events as drafts
|
||||
|
||||
1. Under **Migrate from The Events Calendar**, click **Copy events as drafts**. Keep the tab open until the migration summary appears. Large calendars take time to process in batches.
|
||||
2. Check the copied, already copied, and need review totals. Each new event is saved as an eventLabs draft. The copy includes event descriptions, saved occurrence dates, categories, tags, featured images, and linked venues, organizers, and series. Source records remain available for comparison.
|
||||
3. Review the warnings by source event ID. For a missing or invalid schedule, restore or correct the dates in the source calendar and run the copy again. If a request pauses, click **Copy events as drafts** again. A new run skips existing copies, so it can safely pick up the remaining source events.
|
||||
|
||||
Imported recurring events keep their saved dates. Set a repeat rule in eventLabs if you need it to generate new occurrences. Set up ticketing, registrations, and calendar display settings separately.
|
||||
|
||||
## 4. Apply a template after copying (optional)
|
||||
|
||||
1. Open **Events → Import and Export** and choose a published **Single event template**.
|
||||
2. Click **Apply template to copied events** and wait for the assignment summary. This sets the layout on the existing copies from The Events Calendar, including published copies. It replaces their current template choices.
|
||||
3. Use the **Single Event Template** box in the event editor to adjust an individual event. Preview a draft or open a published event to check the layout. If an already published page still shows a previous layout, clear your host's page cache and reload it.
|
||||
|
||||
## 5. Review, publish, and check the calendar
|
||||
|
||||
1. Open the eventLabs **Events** list and filter to **Draft**. Review the schedule, links, and template on representative events. Check a recurring event by opening different dates on the calendar.
|
||||
2. Publish individual drafts from their editor. To publish a selection, select the drafts in the list, choose **Bulk actions → Edit**, click **Apply**, set **Status** to **Published**, and click **Update**. Repeat for the next page as needed. Review any linked venues, organizers, or series that are still drafts before publishing those too.
|
||||
3. On the clone, deactivate The Events Calendar when testing eventLabs as the public calendar so eventLabs can serve the calendar and event URLs. Open **Events → Settings → View calendar** and check the list, month, and individual event pages. Choose **Past events** in List view to see historical events.
|
||||
@@ -29,3 +29,11 @@ The command uses `EVENTLABS_RELEASE_TOKEN` if set, or your configured Git creden
|
||||
The installed plugin uses WordPress's [external update hook](https://developer.wordpress.org/reference/hooks/update_plugins_hostname/) and Gitea's [latest stable release API](https://docs.gitea.com/api/operations/repo-get-latest-release/). WordPress downloads the attached ZIP over HTTPS and eventLabs verifies its size and checksum. Sites can use **Dashboard → Updates → Check again** to refresh the update list. WordPress's normal auto-update setting controls whether updates install automatically.
|
||||
|
||||
Keep the release downloads public for sites to receive updates without a Gitea account. Installations older than **0.5.2** need the first ZIP uploaded manually. Use a normal plugin installation to test the WordPress upgrade; the Docker development site's bind mount is updated through the Git checkout.
|
||||
|
||||
## Loop Builder add-on releases
|
||||
|
||||
Build the add-on from a committed revision with `python3 scripts/release.py --loop-builder`. The build writes a separate WordPress ZIP and `eventlabs-loop-builder-release.json` to `dist/`.
|
||||
|
||||
Update both version values in `addons/eventlabs-loop-builder/eventlabs-loop-builder.php`, commit the changes, then push `loop-builder-vX.Y.Z`. The [add-on workflow](../.gitea/workflows/loop-builder-release.yml) publishes its own ZIP and checksum manifest under that tag. Gitea marks add-on releases as pre-releases so WordPress's existing eventLabs core update feed continues to point to the latest core ZIP. Users install the add-on ZIP separately through WordPress.
|
||||
|
||||
To publish manually after pushing the tag, run `python3 scripts/release.py --loop-builder loop-builder-vX.Y.Z --publish`.
|
||||
|
||||
@@ -47,7 +47,7 @@ final class Api {
|
||||
}
|
||||
}
|
||||
|
||||
private static function table(): string {
|
||||
public static function table(): string {
|
||||
global $wpdb;
|
||||
return $wpdb->prefix . 'eventlabs_external_ids';
|
||||
}
|
||||
@@ -309,6 +309,9 @@ final class Api {
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
if ( ! $id && 'events' === $resource && Legacy_Migration::SOURCE === ( $identity[0] ?? '' ) && ! empty( $payload['migration_template_id'] ) ) {
|
||||
Single_Event_Templates::assign( $saved_id, (int) $payload['migration_template_id'] );
|
||||
}
|
||||
if ( $identity && ! $id && ! $wpdb->insert( self::table(), [
|
||||
'sync_key' => $sync_key, 'post_id' => $saved_id, 'source' => $identity[0], 'external_id' => $identity[1],
|
||||
], [ '%s', '%d', '%s', '%s' ] ) ) {
|
||||
|
||||
@@ -360,7 +360,7 @@ final class Events {
|
||||
public static function query( array $filters ): array {
|
||||
global $wpdb;
|
||||
$table = self::table();
|
||||
$filters += [ 'from' => null, 'to' => null, 'past' => false, 'search' => '', 'category' => '', 'tag' => '', 'location' => '', 'relation' => null, 'scope' => '', 'featured' => false, 'offset' => 0, 'limit' => 20 ];
|
||||
$filters += [ 'from' => null, 'to' => null, 'end_by' => null, 'past' => false, 'order' => '', 'search' => '', 'category' => '', 'tag' => '', 'location' => '', 'relation' => null, 'relations' => [], 'scope' => '', 'featured' => false, 'exclude' => 0, 'offset' => 0, 'limit' => 20 ];
|
||||
$where = [ "p.post_type = 'burn_event'", "p.post_status = 'publish'", "p.post_password = ''" ];
|
||||
$where[] = "NOT EXISTS (SELECT 1 FROM $wpdb->postmeta h WHERE h.post_id = p.ID AND h.meta_key = '_burn_hidden' AND h.meta_value = '1')";
|
||||
if ( '' !== $filters['scope'] ) {
|
||||
@@ -372,27 +372,43 @@ final class Events {
|
||||
if ( $filters['to'] ) {
|
||||
$where[] = $wpdb->prepare( $filters['past'] ? 'o.ends_at <= %s' : 'o.starts_at < %s', $filters['to'] );
|
||||
}
|
||||
if ( $filters['end_by'] ) {
|
||||
$where[] = $wpdb->prepare( 'o.ends_at <= %s', $filters['end_by'] );
|
||||
}
|
||||
if ( $filters['exclude'] ) {
|
||||
$where[] = $wpdb->prepare( 'p.ID <> %d', $filters['exclude'] );
|
||||
}
|
||||
if ( $filters['search'] ) {
|
||||
$like = '%' . $wpdb->esc_like( $filters['search'] ) . '%';
|
||||
$where[] = $wpdb->prepare( '(p.post_title LIKE %s OR p.post_content LIKE %s)', $like, $like );
|
||||
}
|
||||
foreach ( [ 'category' => self::CATEGORY, 'tag' => 'post_tag' ] as $key => $taxonomy ) {
|
||||
if ( $filters[ $key ] ) {
|
||||
$where[] = $wpdb->prepare( "EXISTS (SELECT 1 FROM $wpdb->term_relationships r JOIN $wpdb->term_taxonomy tt ON tt.term_taxonomy_id = r.term_taxonomy_id JOIN $wpdb->terms t ON t.term_id = tt.term_id WHERE r.object_id = p.ID AND tt.taxonomy = %s AND t.slug = %s)", $taxonomy, $filters[ $key ] );
|
||||
$slugs = array_values( (array) $filters[ $key ] );
|
||||
$placeholders = implode( ', ', array_fill( 0, count( $slugs ), '%s' ) );
|
||||
$where[] = $wpdb->prepare( "EXISTS (SELECT 1 FROM $wpdb->term_relationships r JOIN $wpdb->term_taxonomy tt ON tt.term_taxonomy_id = r.term_taxonomy_id JOIN $wpdb->terms t ON t.term_id = tt.term_id WHERE r.object_id = p.ID AND tt.taxonomy = %s AND t.slug IN ($placeholders))", $taxonomy, ...$slugs );
|
||||
}
|
||||
}
|
||||
$relations = array_intersect_key( $filters['relations'], self::RELATIONS );
|
||||
if ( $filters['relation'] ) {
|
||||
[ $type, $id ] = $filters['relation'];
|
||||
$where[] = $wpdb->prepare( "EXISTS (SELECT 1 FROM $wpdb->postmeta m WHERE m.post_id = p.ID AND m.meta_key = %s AND m.meta_value = %s)", '_burn_' . $type, (string) $id );
|
||||
$relations[ $type ] = [ (string) $id ];
|
||||
}
|
||||
foreach ( $relations as $type => $ids ) {
|
||||
if ( $ids ) {
|
||||
$placeholders = implode( ', ', array_fill( 0, count( $ids ), '%s' ) );
|
||||
$where[] = $wpdb->prepare( "EXISTS (SELECT 1 FROM $wpdb->postmeta m WHERE m.post_id = p.ID AND m.meta_key = %s AND m.meta_value IN ($placeholders))", '_burn_' . $type, ...array_values( $ids ) );
|
||||
}
|
||||
}
|
||||
if ( $filters['location'] ) {
|
||||
$like = '%' . $wpdb->esc_like( $filters['location'] ) . '%';
|
||||
$where[] = $wpdb->prepare( "EXISTS (SELECT 1 FROM $wpdb->postmeta m LEFT JOIN $wpdb->posts v ON m.meta_key = '_burn_venue' AND v.ID = CAST(m.meta_value AS UNSIGNED) AND v.post_status = 'publish' LEFT JOIN $wpdb->postmeta a ON a.post_id = v.ID AND a.meta_key = '_burn_address' WHERE m.post_id = p.ID AND (v.post_title LIKE %s OR a.meta_value LIKE %s OR (m.meta_key = '_burn_search_location' AND m.meta_value LIKE %s)))", $like, $like, $like );
|
||||
}
|
||||
if ( $filters['featured'] ) {
|
||||
$where[] = "EXISTS (SELECT 1 FROM $wpdb->postmeta f WHERE f.post_id = p.ID AND f.meta_key = '_burn_featured' AND f.meta_value = '1')";
|
||||
$featured = "EXISTS (SELECT 1 FROM $wpdb->postmeta f WHERE f.post_id = p.ID AND f.meta_key = '_burn_featured' AND f.meta_value = '1')";
|
||||
$where[] = 'regular' === $filters['featured'] ? 'NOT ' . $featured : $featured;
|
||||
}
|
||||
$order = $filters['past'] ? 'DESC' : 'ASC';
|
||||
$order = in_array( $filters['order'], [ 'ASC', 'DESC' ], true ) ? $filters['order'] : ( $filters['past'] ? 'DESC' : 'ASC' );
|
||||
$limit = $wpdb->prepare( ' LIMIT %d OFFSET %d', $filters['limit'], $filters['offset'] );
|
||||
return $wpdb->get_results( "SELECT o.event_id, o.starts_at, o.ends_at FROM $table o JOIN $wpdb->posts p ON p.ID = o.event_id WHERE " . implode( ' AND ', $where ) . " ORDER BY o.starts_at $order, o.event_id $order" . $limit, ARRAY_A ) ?: [];
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ final class Legacy_Migration {
|
||||
private const EVENT = 'tribe_events';
|
||||
private const CATEGORY = 'tribe_events_cat';
|
||||
private const BATCH = 8;
|
||||
private const TEMPLATE_BATCH = 100;
|
||||
private const ACTION = 'burn_events_legacy_migrate';
|
||||
private const TYPES = [ 'venue' => 'tribe_venue', 'organizer' => 'tribe_organizer', 'series' => 'tribe_event_series' ];
|
||||
|
||||
@@ -50,24 +51,60 @@ final class Legacy_Migration {
|
||||
return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft', 'inherit')", self::EVENT ) );
|
||||
}
|
||||
|
||||
private static function copied_count(): int {
|
||||
global $wpdb;
|
||||
$table = Api::table();
|
||||
return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $table x JOIN $wpdb->posts p ON p.ID = x.post_id WHERE x.source = %s AND p.post_type = %s AND p.post_status NOT IN ('trash', 'auto-draft', 'inherit')", self::SOURCE, Events::EVENT ) );
|
||||
}
|
||||
|
||||
public static function section(): void {
|
||||
$count = self::count();
|
||||
if ( ! $count && ! self::installed() ) {
|
||||
$copies = self::copied_count();
|
||||
if ( ! $count && ! $copies && ! self::installed() ) {
|
||||
return;
|
||||
}
|
||||
$templates = $count || $copies ? Single_Event_Templates::migration_templates() : [];
|
||||
?>
|
||||
<section id="eventlabs-migration">
|
||||
<h2><?php esc_html_e( 'Migrate from The Events Calendar', 'burn-events' ); ?></h2>
|
||||
<p><a href="<?php echo esc_url( 'https://git.labs.casa/josh/eventLabs/src/branch/main/docs/MIGRATION.md' ); ?>"><?php esc_html_e( 'Read the migration guide', 'burn-events' ); ?></a></p>
|
||||
<?php if ( ! $count ) : ?>
|
||||
<p><?php esc_html_e( 'The plugin is installed. No events are available to migrate.', 'burn-events' ); ?></p>
|
||||
<p><?php esc_html_e( 'No source events are available to copy.', 'burn-events' ); ?></p>
|
||||
<?php else : ?>
|
||||
<p><?php printf( esc_html( _n( '%s source event found.', '%s source events found.', $count, 'burn-events' ) ), esc_html( number_format_i18n( $count ) ) ); ?></p>
|
||||
<p><?php esc_html_e( 'Copy events as drafts with their saved dates, linked venues, organizers and series, categories, tags, and featured images. The source events stay available for review.', 'burn-events' ); ?></p>
|
||||
<p><?php esc_html_e( 'Imported recurring events use the dates already saved in the source calendar. Set a new repeat rule to generate new dates.', 'burn-events' ); ?></p>
|
||||
<form data-be-migrate action="<?php echo esc_url( admin_url( 'admin-ajax.php', 'relative' ) ); ?>" method="post">
|
||||
<?php endif; ?>
|
||||
<?php if ( $copies ) : ?>
|
||||
<p><?php printf( esc_html( _n( '%s event already copied.', '%s events already copied.', $copies, 'burn-events' ) ), esc_html( number_format_i18n( $copies ) ) ); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if ( ( $count || $copies ) && ! $templates ) : ?>
|
||||
<p><?php esc_html_e( 'To choose an Elementor layout here, activate Elementor and publish a layout under', 'burn-events' ); ?> <a href="<?php echo esc_url( Single_Event_Templates::list_url() ); ?>"><?php esc_html_e( 'Single Event Templates', 'burn-events' ); ?></a>.</p>
|
||||
<?php endif; ?>
|
||||
<?php if ( $count || ( $copies && $templates ) ) : ?>
|
||||
<form data-be-migrate data-has-copies="<?php echo $copies ? '1' : '0'; ?>" action="<?php echo esc_url( admin_url( 'admin-ajax.php', 'relative' ) ); ?>" method="post">
|
||||
<input type="hidden" name="action" value="<?php echo esc_attr( self::ACTION ); ?>">
|
||||
<?php wp_nonce_field( self::ACTION ); ?>
|
||||
<button type="submit" class="button button-primary" disabled><?php esc_html_e( 'Copy events as drafts', 'burn-events' ); ?></button>
|
||||
<?php if ( $templates ) : ?>
|
||||
<p>
|
||||
<label for="be-migration-template"><?php esc_html_e( 'Single event template', 'burn-events' ); ?></label>
|
||||
<select id="be-migration-template" name="template_id" aria-describedby="be-migration-template-help">
|
||||
<option value="0"><?php esc_html_e( 'Inherit site default', 'burn-events' ); ?></option>
|
||||
<?php foreach ( $templates as $template ) : ?>
|
||||
<option value="<?php echo esc_attr( (string) $template->ID ); ?>"><?php echo esc_html( get_the_title( $template ) ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</p>
|
||||
<p class="description" id="be-migration-template-help"><?php esc_html_e( 'Choose a template for new copies. Applying it to copied events replaces their current template, including on published events.', 'burn-events' ); ?></p>
|
||||
<?php endif; ?>
|
||||
<p>
|
||||
<?php if ( $count ) : ?>
|
||||
<button type="submit" class="button button-primary" data-be-operation value="copy" disabled><?php esc_html_e( 'Copy events as drafts', 'burn-events' ); ?></button>
|
||||
<?php endif; ?>
|
||||
<?php if ( $templates ) : ?>
|
||||
<button type="submit" class="button" data-be-operation value="apply" disabled><?php esc_html_e( 'Apply template to copied events', 'burn-events' ); ?></button>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<p data-be-migrate-status role="status"></p>
|
||||
<ul data-be-migrate-errors></ul>
|
||||
</form>
|
||||
@@ -83,11 +120,20 @@ final class Legacy_Migration {
|
||||
wp_send_json_error( __( 'Refresh the migration page and sign in as an administrator.', 'burn-events' ), $signed_in ? 403 : 401 );
|
||||
}
|
||||
$after = is_scalar( $_POST['after'] ?? null ) ? absint( $_POST['after'] ) : 0;
|
||||
$operation = $_POST['operation'] ?? 'copy';
|
||||
$template_id = $_POST['template_id'] ?? '0';
|
||||
if ( ! in_array( $operation, [ 'copy', 'apply' ], true ) || ! is_scalar( $template_id ) || ! ctype_digit( (string) $template_id ) ) {
|
||||
wp_send_json_error( __( 'Choose a valid migration action and template.', 'burn-events' ), 400 );
|
||||
}
|
||||
$template_id = (int) $template_id;
|
||||
// Other plugins may print during post creation. Keep that output out of the JSON response.
|
||||
$buffer_level = ob_get_level();
|
||||
ob_start();
|
||||
try {
|
||||
$result = self::batch( $after );
|
||||
$result = 'apply' === $operation ? self::apply_template_batch( $after, $template_id ) : self::batch( $after, $template_id );
|
||||
} catch ( InvalidArgumentException $error ) {
|
||||
$validation_error = $error->getMessage();
|
||||
$result = null;
|
||||
} catch ( \Throwable ) {
|
||||
$result = null;
|
||||
} finally {
|
||||
@@ -95,14 +141,21 @@ final class Legacy_Migration {
|
||||
// Close only buffers opened while copying this batch.
|
||||
}
|
||||
}
|
||||
if ( isset( $validation_error ) ) {
|
||||
wp_send_json_error( $validation_error, 400 );
|
||||
}
|
||||
if ( null === $result ) {
|
||||
wp_send_json_error( __( 'The source calendar could not be read. You can retry the migration.', 'burn-events' ), 500 );
|
||||
$message = 'apply' === $operation ? __( 'The copied events could not be updated. You can retry the template assignment.', 'burn-events' ) : __( 'The source calendar could not be read. You can retry the migration.', 'burn-events' );
|
||||
wp_send_json_error( $message, 500 );
|
||||
}
|
||||
wp_send_json_success( $result );
|
||||
}
|
||||
|
||||
public static function batch( int $after ): array {
|
||||
public static function batch( int $after, int $template_id = 0 ): array {
|
||||
global $wpdb;
|
||||
if ( $template_id ) {
|
||||
self::require_template( $template_id );
|
||||
}
|
||||
$ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s AND ID > %d AND post_status NOT IN ('trash', 'auto-draft', 'inherit') ORDER BY ID LIMIT %d", self::EVENT, $after, self::BATCH + 1 ) );
|
||||
if ( $wpdb->last_error ) {
|
||||
throw new RuntimeException( 'Source event query failed.' );
|
||||
@@ -112,7 +165,7 @@ final class Legacy_Migration {
|
||||
foreach ( array_slice( $ids, 0, self::BATCH ) as $id ) {
|
||||
$after = (int) $id;
|
||||
try {
|
||||
++$result[ self::event( $after ) ];
|
||||
++$result[ self::event( $after, $template_id ) ];
|
||||
} catch ( InvalidArgumentException $error ) {
|
||||
$result['errors'][] = sprintf( __( 'Event #%1$d — %2$s', 'burn-events' ), $after, $error->getMessage() );
|
||||
} catch ( \Throwable $error ) {
|
||||
@@ -123,7 +176,43 @@ final class Legacy_Migration {
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function event( int $id ): string {
|
||||
private static function require_template( int $template_id ): void {
|
||||
if ( ! Single_Event_Templates::can_use_for_migration( $template_id ) ) {
|
||||
throw new InvalidArgumentException( __( 'Choose a published template built with Elementor. Refresh the migration page if the template changed.', 'burn-events' ) );
|
||||
}
|
||||
}
|
||||
|
||||
public static function apply_template_batch( int $after, int $template_id ): array {
|
||||
global $wpdb;
|
||||
self::require_template( $template_id );
|
||||
$table = Api::table();
|
||||
$ids = $wpdb->get_col( $wpdb->prepare( "SELECT p.ID FROM $table x JOIN $wpdb->posts p ON p.ID = x.post_id WHERE x.source = %s AND p.post_type = %s AND p.ID > %d AND p.post_status NOT IN ('trash', 'auto-draft', 'inherit') ORDER BY p.ID LIMIT %d", self::SOURCE, Events::EVENT, $after, self::TEMPLATE_BATCH + 1 ) );
|
||||
if ( $wpdb->last_error ) {
|
||||
throw new RuntimeException( 'Copied event query failed.' );
|
||||
}
|
||||
$result = [ 'applied' => 0, 'skipped' => 0, 'errors' => [], 'next' => 0 ];
|
||||
foreach ( array_slice( $ids, 0, self::TEMPLATE_BATCH ) as $id ) {
|
||||
$after = (int) $id;
|
||||
if ( ! current_user_can( 'edit_post', $after ) ) {
|
||||
$result['errors'][] = sprintf( __( 'You cannot edit event #%d.', 'burn-events' ), $after );
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if ( Single_Event_Templates::assign( $after, $template_id ) ) {
|
||||
clean_post_cache( $after );
|
||||
++$result['applied'];
|
||||
} else {
|
||||
++$result['skipped'];
|
||||
}
|
||||
} catch ( \Throwable ) {
|
||||
$result['errors'][] = sprintf( __( 'The template could not be assigned to event #%d.', 'burn-events' ), $after );
|
||||
}
|
||||
}
|
||||
$result['next'] = count( $ids ) > self::TEMPLATE_BATCH ? $after : 0;
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function event( int $id, int $template_id ): string {
|
||||
$source = get_post( $id );
|
||||
if ( ! $source || self::EVENT !== $source->post_type || 'trash' === $source->post_status ) {
|
||||
throw new InvalidArgumentException( __( 'The source event is unavailable.', 'burn-events' ) );
|
||||
@@ -146,6 +235,9 @@ final class Legacy_Migration {
|
||||
'hidden' => self::flag( $id, '_EventHideFromUpcoming' ),
|
||||
'metadata' => [ 'migration' => [ 'source_post_id' => $id, 'source_status' => $source->post_status, 'saved_dates' => count( $dates ) ] ],
|
||||
];
|
||||
if ( $template_id ) {
|
||||
$payload['migration_template_id'] = $template_id;
|
||||
}
|
||||
foreach ( self::TYPES as $type => $post_type ) {
|
||||
$payload[ $type ] = [];
|
||||
$links = 'series' === $type ? self::series_ids( $id ) : get_post_meta( $id, '_Event' . ucfirst( $type ) . 'ID', false );
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace BurnEvents;
|
||||
|
||||
use Elementor\Core\Base\Document;
|
||||
use Elementor\Plugin as Elementor;
|
||||
use InvalidArgumentException;
|
||||
use WP_Post;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
@@ -151,6 +152,41 @@ final class Single_Event_Templates {
|
||||
return (int) get_post_meta( $event_id, self::EVENT_TEMPLATE_META, true );
|
||||
}
|
||||
|
||||
private static function published_templates(): array {
|
||||
return get_posts( [
|
||||
'post_type' => self::POST_TYPE, 'post_status' => 'publish', 'has_password' => false,
|
||||
'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC',
|
||||
] );
|
||||
}
|
||||
|
||||
public static function migration_templates(): array {
|
||||
if ( ! self::is_elementor_ready() ) {
|
||||
return [];
|
||||
}
|
||||
return array_filter( self::published_templates(), static fn( WP_Post $post ): bool => self::can_use_for_migration( $post->ID ) );
|
||||
}
|
||||
|
||||
public static function can_use_for_migration( int $template_id ): bool {
|
||||
if ( $template_id < 1 || ! self::is_elementor_ready() || ! self::is_layout( get_post( $template_id ) ) ) {
|
||||
return false;
|
||||
}
|
||||
$document = Elementor::instance()->documents->get( $template_id );
|
||||
$data = get_post_meta( $template_id, Document::ELEMENTOR_DATA_META_KEY, true );
|
||||
$elements = is_string( $data ) ? json_decode( $data, true ) : null;
|
||||
return $document instanceof Document && $document->is_built_with_elementor() && is_array( $elements ) && $elements && array_is_list( $elements );
|
||||
}
|
||||
|
||||
public static function assign( int $event_id, int $template_id ): bool {
|
||||
if ( $event_id < 1 || self::EVENT !== get_post_type( $event_id ) || $template_id < 1 || ! self::is_layout( get_post( $template_id ) ) ) {
|
||||
throw new InvalidArgumentException( __( 'The event or published template is unavailable.', 'burn-events' ) );
|
||||
}
|
||||
if ( self::get_assignment( $event_id ) === $template_id ) {
|
||||
return false;
|
||||
}
|
||||
Events::write_meta( $event_id, self::EVENT_TEMPLATE_META, (string) $template_id );
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function render( WP_Post $event, ?array $row ): string {
|
||||
if ( ! self::is_elementor_ready() || Elementor::instance()->preview->is_preview_mode() ) {
|
||||
return '';
|
||||
@@ -216,16 +252,7 @@ final class Single_Event_Templates {
|
||||
|
||||
public static function assignment_box( WP_Post $post ): void {
|
||||
$selected = self::get_assignment( $post->ID );
|
||||
$templates = get_posts(
|
||||
[
|
||||
'post_type' => self::POST_TYPE,
|
||||
'post_status' => 'publish',
|
||||
'has_password' => false,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
]
|
||||
);
|
||||
$templates = self::published_templates();
|
||||
wp_nonce_field( 'burn_events_save_assignment', 'burn_events_assignment_nonce' );
|
||||
?>
|
||||
<label class="screen-reader-text" for="burn-events-assignment"><?php esc_html_e( 'Single Event Template', 'burn-events' ); ?></label>
|
||||
|
||||
@@ -10,11 +10,12 @@ from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from tempfile import TemporaryDirectory
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import urlencode
|
||||
from urllib.request import HTTPRedirectHandler, Request, build_opener
|
||||
from uuid import uuid4
|
||||
from zipfile import ZipFile
|
||||
from zipfile import ZIP_DEFLATED, ZipFile
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
@@ -28,6 +29,10 @@ REQUIREMENT = r'[0-9]+\.[0-9]+(?:\.[0-9]+)?'
|
||||
RUNTIME = ('burn-events.php', 'assets', 'includes', 'templates')
|
||||
MAX_ZIP_BYTES = 32 * 1024 * 1024
|
||||
USER_AGENT = 'eventLabs-release'
|
||||
ADDON = 'eventlabs-loop-builder'
|
||||
ADDON_SOURCE = f'addons/{ADDON}/'
|
||||
ADDON_MAIN = f'{ADDON}.php'
|
||||
ADDON_MANIFEST = f'{ADDON}-release.json'
|
||||
|
||||
|
||||
def git(*args):
|
||||
@@ -87,6 +92,64 @@ def build(ref, output):
|
||||
return tag, data, archive, manifest
|
||||
|
||||
|
||||
def build_loop_builder(ref, output):
|
||||
commit = git('rev-parse', '--verify', '--end-of-options', ref + '^{commit}').decode().strip()
|
||||
source = git('show', commit + ':' + ADDON_SOURCE + ADDON_MAIN).decode()
|
||||
|
||||
def header(name, pattern):
|
||||
found = re.findall(r'^\s*\* ' + re.escape(name) + r': (' + pattern + r')\s*$', source, re.M)
|
||||
if len(found) != 1:
|
||||
raise ValueError(f'Expected one valid {name} header in {ADDON_MAIN}.')
|
||||
return found[0]
|
||||
|
||||
version = header('Version', VERSION)
|
||||
tag = 'loop-builder-v' + version
|
||||
if f"const VERSION = '{version}';" not in source:
|
||||
raise ValueError('The Loop Builder version header and constant must match.')
|
||||
if (ref.startswith('refs/tags/') or re.fullmatch('loop-builder-v' + VERSION, ref)) and ref.removeprefix('refs/tags/') != tag:
|
||||
raise ValueError(f'Loop Builder release tag must match its version: {tag}.')
|
||||
core = re.findall(r"^const CORE_MINIMUM = '(" + VERSION + r")';$", source, re.M)
|
||||
if len(core) != 1 or header('Requires Plugins', r'[^\r\n]+') != 'burn-events, elementor':
|
||||
raise ValueError('The Loop Builder must declare its eventLabs and Elementor dependencies.')
|
||||
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
archive = output / f'{ADDON}-v{version}.zip'
|
||||
with TemporaryDirectory(dir=output) as temp:
|
||||
raw = Path(temp) / 'tagged-source.zip'
|
||||
candidate = Path(temp) / archive.name
|
||||
paths = [ADDON_SOURCE + file for file in (ADDON_MAIN, 'README.md', 'includes', 'assets')]
|
||||
subprocess.run(
|
||||
['git', '-C', str(ROOT), 'archive', '--format=zip', '--output=' + str(raw.resolve()), commit, '--', *paths],
|
||||
check=True, env={**os.environ, 'TZ': 'UTC'},
|
||||
)
|
||||
with ZipFile(raw) as tagged, ZipFile(candidate, 'w', ZIP_DEFLATED, compresslevel=9) as package:
|
||||
for entry in tagged.infolist():
|
||||
if entry.is_dir():
|
||||
continue
|
||||
path = entry.filename.removeprefix(ADDON_SOURCE)
|
||||
body = tagged.read(entry)
|
||||
entry.filename = f'{ADDON}/{path}'
|
||||
entry.orig_filename = entry.filename
|
||||
package.writestr(entry, body, compress_type=ZIP_DEFLATED, compresslevel=9)
|
||||
with ZipFile(candidate) as package:
|
||||
if package.read(f'{ADDON}/{ADDON_MAIN}').decode() != source or package.testzip() is not None:
|
||||
raise ValueError('The Loop Builder ZIP is incomplete or corrupt.')
|
||||
size = candidate.stat().st_size
|
||||
if not 0 < size <= MAX_ZIP_BYTES:
|
||||
raise ValueError('The WordPress release ZIP must be at most 32 MiB.')
|
||||
data = {
|
||||
'version': version, 'requires': header('Requires at least', REQUIREMENT),
|
||||
'requires_php': header('Requires PHP', REQUIREMENT), 'requires_eventlabs': core[0],
|
||||
'package': archive.name, 'commit': commit, 'size': size,
|
||||
'sha256': hashlib.sha256(candidate.read_bytes()).hexdigest(),
|
||||
}
|
||||
candidate.replace(archive)
|
||||
manifest = output / ADDON_MANIFEST
|
||||
manifest.write_text(json.dumps(data, indent=2) + '\n', encoding='utf-8')
|
||||
print(f'Built {archive} and {manifest}', flush=True)
|
||||
return tag, data, archive, manifest
|
||||
|
||||
|
||||
class NoRedirect(HTTPRedirectHandler):
|
||||
def redirect_request(self, *args, **kwargs):
|
||||
# API write requests must never forward a repository credential to a redirect target.
|
||||
@@ -109,7 +172,7 @@ def authorization():
|
||||
return 'Basic ' + encoded
|
||||
|
||||
|
||||
def publish(tag, data, archive, manifest):
|
||||
def publish(tag, data, archive, manifest, *, addon=False):
|
||||
auth = authorization()
|
||||
opener = build_opener(NoRedirect())
|
||||
|
||||
@@ -140,15 +203,21 @@ def publish(tag, data, archive, manifest):
|
||||
if remote_tag.get('commit', {}).get('sha') != data['commit']:
|
||||
raise ValueError(f'Push {tag} for this exact commit before publishing.')
|
||||
marker = f"SHA-256: `{data['sha256']}`"
|
||||
name = 'eventLabs Loop Builder v' + data['version'] if addon else 'eventLabs ' + tag
|
||||
requirements = (
|
||||
f"Requires eventLabs {data['requires_eventlabs']} or later and Elementor.\n\n"
|
||||
f"[Setup and usage guide]({HOST}{REPO}/src/tag/{tag}/{ADDON_SOURCE}README.md)\n\n"
|
||||
if addon else ''
|
||||
)
|
||||
release = api('GET', '/releases/tags/' + tag, missing=True)
|
||||
if release is None:
|
||||
release = api('POST', '/releases', payload={
|
||||
'tag_name': tag, 'target_commitish': data['commit'], 'name': f'eventLabs {tag}',
|
||||
'draft': True, 'prerelease': False,
|
||||
'tag_name': tag, 'target_commitish': data['commit'], 'name': name,
|
||||
'draft': True, 'prerelease': addon,
|
||||
'body': f"Install `{archive.name}` through Plugins → Add Plugin → Upload Plugin.\n\n"
|
||||
f"Source commit: `{data['commit']}`\n\n{marker}",
|
||||
f"{requirements}Source commit: `{data['commit']}`\n\n{marker}",
|
||||
})
|
||||
if release.get('tag_name') != tag or release.get('prerelease') or marker not in (release.get('body') or ''):
|
||||
if release.get('tag_name') != tag or release.get('prerelease') is not addon or marker not in (release.get('body') or ''):
|
||||
raise ValueError(f'An existing release for {tag} does not match this package. Check it on Gitea.')
|
||||
attachments = {asset['name']: asset['size'] for asset in release.get('assets') or []}
|
||||
if release.get('draft'):
|
||||
@@ -179,15 +248,18 @@ def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('ref', nargs='?', default='HEAD', help='Git ref to package; default HEAD')
|
||||
parser.add_argument('--out', type=Path, default=ROOT / 'dist')
|
||||
parser.add_argument('--loop-builder', action='store_true', help='Package the separately installable Loop Builder add-on')
|
||||
parser.add_argument('--publish', action='store_true', help='Publish both assets to the already pushed tag')
|
||||
args = parser.parse_args()
|
||||
if args.publish and not re.fullmatch('v' + VERSION, args.ref):
|
||||
parser.error('--publish requires a stable tag like v0.5.2')
|
||||
prefix = 'loop-builder-v' if args.loop_builder else 'v'
|
||||
if args.publish and not re.fullmatch(prefix + VERSION, args.ref):
|
||||
parser.error(f'--publish requires a {prefix}X.Y.Z tag')
|
||||
ref = 'refs/tags/' + args.ref if args.publish else args.ref
|
||||
try:
|
||||
release = build(ref, args.out)
|
||||
builder = build_loop_builder if args.loop_builder else build
|
||||
release = builder(ref, args.out)
|
||||
if args.publish:
|
||||
publish(*release)
|
||||
publish(*release, addon=args.loop_builder)
|
||||
except (ValueError, OSError, subprocess.CalledProcessError, URLError) as error:
|
||||
print(f'Release failed: {error}', file=sys.stderr)
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user