-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
class TicketioBridge extends BridgeAbstract | ||
{ | ||
const NAME = 'Ticket.io Bridge'; | ||
const DESCRIPTION = 'Provides updates for available events in a specific ticketshop on ticket.io'; | ||
const MAINTAINER = 'SebLaus'; | ||
const CACHE_TIMEOUT = 60*60*12; // 12 hours | ||
const PARAMETERS = [ | ||
[ | ||
'Link' => [ | ||
'name' => 'Link to Ticketpage', | ||
'required' => true, | ||
'exampleValue' => 'https://gotogotec.ticket.io' | ||
] | ||
] | ||
]; | ||
|
||
public function collectData() { | ||
$html = getSimpleHTMLDOM($this->getInput('Link')); | ||
|
||
if (!$html) { | ||
returnServerError('Could not retrieve website content.'); | ||
} | ||
|
||
// Find all event rows | ||
$eventRows = $html->find('tr.container'); | ||
|
||
foreach ($eventRows as $eventRow) { | ||
// Get the event name | ||
$eventName = $eventRow->find('a.a-eventlink', 0)->plaintext; | ||
|
||
// Reduce eventName length if too long | ||
if(strlen($eventName) > 35) { | ||
$eventName = substr($eventName,0,35); | ||
} | ||
|
||
// Find the list item containing the date | ||
$dateElement = $eventRow->find('ul.fa-ul li span', 1); // Second <span> inside the list item | ||
|
||
// Check if the date element is found | ||
if ($dateElement) { | ||
$eventDate = $dateElement->plaintext; | ||
} else { | ||
$eventDate = 'Date not found'; | ||
} | ||
|
||
// Build title out of Name and Date | ||
$eventTitle = $eventName . ' - ' . $eventDate; | ||
|
||
// Link to the event page | ||
$eventLink = $this->getInput('Link') . $eventRow->find('a.a-eventlink', 0)->href; | ||
|
||
// Create a feed item with the title and link | ||
$item = []; | ||
$item['title'] = $eventTitle; | ||
$item['uri'] = $eventLink; | ||
$item['content'] = "<p><a href='$eventLink'>More details</a></p>"; | ||
|
||
$this->items[] = $item; | ||
} | ||
} | ||
} |