source: trunk/Modules/Event/Event.php

Last change on this file was 63, checked in by chronos, 3 years ago
  • Modified: Used explicit types where possible for better error reporting.
  • Modified: Updated Common packaged to newer version.
  • Modified: Simplified pages title.
  • Added: Simple keyword based spam filter for meet items.
File size: 3.6 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/Import/JoeClub.php');
4
5function GetDefaultEventFilter(string $Table = ''): string
6{
7 global $Config;
8
9 if ($Table != '') $Table = $Table.'.';
10
11 return '('.$Table.'Hidden=0) AND ('.$Table.'TimeFrom > "'.TimeToMysqlDateTime(time() - (int)$Config['EventInterval']).'")';
12}
13
14function ReduceSpaces(string $Content): string
15{
16 while (strpos($Content, ' ') !== false) $Content = str_replace(' ', ' ', $Content);
17 return $Content;
18}
19
20function RemoveLines(string $Content): string
21{
22 while (strpos($Content, "\n") !== false) $Content = str_replace("\n", ' ', $Content);
23 return $Content;
24}
25
26function RemoveTabs(string $Content): string
27{
28 while (strpos($Content, "\t") !== false) $Content = str_replace("\t", '', $Content);
29 return $Content;
30}
31
32class EventSources
33{
34 public $Database;
35
36 function Parse(int $Id = null): string
37 {
38 $Output = '';
39 if (($Id != null) and is_numeric($Id)) $Where = 'Id='.$Id;
40 else $Where = '1';
41 $DbResult = $this->Database->select('EventSource', '*', $Where);
42 while ($DbRow = $DbResult->fetch_assoc())
43 {
44 $Method = $DbRow['Method'];
45 if ($Method == 'joe') $Source = new EventSourceJoeClub();
46 else {
47 $Output .= 'Unsupported parse method: '.$Method.'<br/>';
48 continue;
49 }
50 $Source->Database = $this->Database;
51 $Source->Id = $DbRow['Id'];
52 $Source->URL = $DbRow['URL'];
53 $Source->Method = $Method;
54 $Source->Name = $DbRow['Name'];
55 $this->Items[] = $Source;
56 $Output .= $Source->Import();
57 }
58 return $Output;
59 }
60}
61
62class EventSource
63{
64 public $Name;
65 public $URL;
66 public $Method;
67 public $Id;
68 public $Database;
69 public $AddedCount;
70
71 function ImportInternal()
72 {
73 }
74
75 function Import(): string
76 {
77 $this->AddedCount = 0;
78 $Output = 'Parsing '.$this->Name.' ('.$this->Id.')...';
79 $this->ImportInternal();
80 $Output .= 'done.';
81 if ($this->AddedCount > 0) $Output .= ' '.$this->AddedCount.' new.';
82 $Output .= '</br>'."\n";
83 return $Output;
84 }
85}
86
87class Event
88{
89 var $Database;
90 var $Title = '';
91 var $Description = '';
92 var $TimeFrom = '';
93 var $TimeTo = '';
94 var $Source = 0;
95 var $Location = '';
96 var $Image = '';
97 var $Link = '';
98 var $RemoteId = '';
99 var $Price = 0;
100
101 function AddIfNotExist(int $TimeInterval = 0, bool $CompareTime = true, bool $CompareRemoteId = false): int
102 {
103 $Where = '(`Description` = "'.$this->Database->real_escape_string($this->Description).'") AND '.
104 '(`Title` = "'.$this->Database->real_escape_string($this->Title).'") AND '.
105 '(`Source` = '.$this->Source.')';
106 if ($CompareTime)
107 $Where .= ' AND (`TimeFrom` >= "'.$this->Database->real_escape_string(TimeToMysqlDateTime($this->TimeFrom - $TimeInterval)).'") AND '.
108 '(`TimeFrom` <= "'.$this->Database->real_escape_string(TimeToMysqlDateTime($this->TimeFrom + $TimeInterval)).'")';
109 if ($CompareRemoteId)
110 $Where .= ' AND (`RemoteId` = "'.$this->Database->real_escape_string($this->RemoteId).'")';
111 $DbResult = $this->Database->select('Event', '*', $Where);
112 if ($DbResult->num_rows == 0)
113 {
114 $this->Database->insert('Event', array(
115 'Title' => $this->Title,
116 'Description' => $this->Description,
117 'TimeFrom' => TimeToMysqlDateTime($this->TimeFrom),
118 'TimeTo' => TimeToMysqlDateTime($this->TimeTo),
119 'Location' => $this->Location,
120 'Source' => $this->Source,
121 'Link' => $this->Link,
122 'Price' => $this->Price,
123 'RemoteId' => $this->RemoteId,
124 'TimeImport' => 'NOW()',
125 ));
126 $Result = 1;
127 } else $Result = 0;
128 return $Result;
129 }
130}
Note: See TracBrowser for help on using the repository browser.