4 * Event Calendar for Elxis CMS 2008.x and 2009.x
9 * @package eventCalendar
10 * @author Apostolos Koutsoulelos <akoutsoulelos@yahoo.gr>
11 * @copyright Copyright (C) 2009-2010 Apostolos Koutsoulelos. All rights reserved.
12 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
16 // Prevent direct inclusion of this file
17 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
19 if (!defined('EVCALBASE')) {
21 if ($_VERSION->RELEASE
> 2008) {
22 define('EVCALBASE', 'events');
24 define('EVCALBASE', 'com_eventcalendar');
28 // Generate SEO Pro page
29 function seogen_com_eventcalendar($link) {
30 global $mosConfig_live_site, $database;
32 if (trim($link) == '') { return ''; }
34 $database->setQuery( "SELECT params FROM #__components WHERE link = 'option=com_eventcalendar'" );
35 $text = $database->loadResult();
36 $config_values = new mosParameters( $text );
39 $vars['option'] = 'com_eventcalendar';
42 $vars['eventid'] = '';
48 $half = preg_split('/[\?]/', $link);
49 if (isset($half[1])) {
50 $half2 = preg_split('/[\#]/', $half[1]);
51 $parts = preg_split('/[\&]/', $half2[0], -1, PREG_SPLIT_NO_EMPTY
);
52 if (count($parts) >0) {
53 foreach ($parts as $part) {
54 list($x, $y) = preg_split('/[\=]/', $part, 2);
61 // Get event SEO title
62 if ($vars['eventid']) {
63 $query = "SELECT seotitle FROM #__eventcalendar WHERE id='".$vars['eventid']."'";
64 $database->setQuery($query, '#__', 1, 0);
65 $eventseo = $database->loadResult();
70 // Get categories SEO titles
71 if ($vars['catid']) { // categories are set
72 $catid = split( " ", $vars['catid'] );
73 if (count($catid) == 1) {
74 $key = array_keys($catid);
75 $catid = $catid[$key[0]];
77 } else { // no category is set
80 $query = "SELECT seotitle FROM #__categories WHERE section='com_eventcalendar'";
81 if (is_array( $catid )) {
82 $query .= "\n AND id IN (" . implode( ",", $catid ) . ")";
84 $query .= "\n AND id = " .$catid;
86 $database->setQuery($query);
87 $catseo = $database->loadResultArray();
89 // Generate SEO Pro page depending task
90 switch ($vars['task']) {
92 return $mosConfig_live_site.'/'.EVCALBASE
.'/editevent/save.html';
95 return $mosConfig_live_site.'/'.EVCALBASE
.'/editevent/cancel.html';
98 return $mosConfig_live_site.'/'.EVCALBASE
.'/editevent/'.( ($eventseo)?
($eventseo.'.html'):'' );
101 return $mosConfig_live_site.'/'.EVCALBASE
.'/'.$eventseo.'.html';
104 return $mosConfig_live_site.'/'.EVCALBASE
.'/'.(($catid)?
implode("+", $catseo):'all').'/'.$vars['year'].'/'.$vars['month'].'/';
107 $vars['week'] = (strlen($vars['week']) == 1)?
'0'.$vars['week']:$vars['week'];
108 return $mosConfig_live_site.'/'.EVCALBASE
.'/'.(($catid)?
implode("+", $catseo):'all').'/'.$vars['year'].'/'.$vars['week'].'.html';
111 $vars['day'] = (strlen($vars['day']) == 1)?
'0'.$vars['day']:$vars['day'];
112 return $mosConfig_live_site.'/'.EVCALBASE
.'/'.(($catid)?
implode("+", $catseo):'all').'/'.$vars['year'].'/'.$vars['month'].'/'.$vars['day'].'.html';
115 return $mosConfig_live_site.'/'.EVCALBASE
.'/'.(($catid)?
implode("+", $catseo):'all').'/';
118 return $mosConfig_live_site.'/'.EVCALBASE
.'/syndication.html';
121 return $mosConfig_live_site.'/'.EVCALBASE
.'/';
126 // Restore original page
127 function seores_com_eventcalendar($seolink='', $register_globals=0) {
128 global $database, $lang;
130 $seolink = urldecode($seolink);
131 $seolink = trim(preg_replace('/(&)/', '&', $seolink));
132 $link = preg_split('/[\?]/', $seolink);
133 $itemsyn = intval(mosGetParam( $_SESSION, 'itemsyn', 0 ));
135 $QUERY_STRING = array();
137 $_GET['option'] = 'com_eventcalendar';
138 $_REQUEST['option'] = 'com_eventcalendar';
139 $QUERY_STRING[] = 'option=com_eventcalendar';
141 if ( ($link[0] == EVCALBASE
.'/') ||
($link[0] == EVCALBASE
) ) { // URL = ../events/ OR URL = ../events
143 $_REQUEST['catid'] = '';
144 $QUERY_STRING[] = 'catid=';
146 $database->setQuery( "SELECT params FROM #__components WHERE link = 'option=com_eventcalendar'" );
147 $text = $database->loadResult();
148 $com_params = new mosParameters( $text );
150 $task = $com_params->get('default_view', 'monthview');
151 $_GET['task'] = $task;
152 $_REQUEST['task'] = $task;
153 $QUERY_STRING[] = 'task='.$task;
155 $_GET['year'] = date("Y", time());
156 $_REQUEST['year'] = date("Y", time());
157 $QUERY_STRING[] = 'year=' . date("Y", time());
159 $_GET['month'] = date("m", time());
160 $_REQUEST['month'] = date("m", time());
161 $QUERY_STRING[] = 'month=' . date("m", time());
163 $_GET['day'] = date("d", time());
164 $_REQUEST['day'] = date("d", time());
165 $QUERY_STRING[] = 'day=' . date("d", time());
167 $parts = preg_split('/[\/]/', $link[0]);
168 if ((!isset($parts[2])) && (substr($parts[1], -4) == 'html')) { // URL = ../events/[$event_seotitle].html or ../events/syndication.html
169 $eventseo = preg_replace('/(\.html)$/', '', $parts[1]);
170 if ($eventseo == 'syndication') {
171 $_GET['task'] = 'syndication';
172 $_REQUEST['task'] = 'syndication';
173 $QUERY_STRING[] = 'task=syndication';
175 $_GET['task'] = 'eventview';
176 $_REQUEST['task'] = 'eventview';
177 $QUERY_STRING[] = 'task=eventview';
179 $query = "SELECT id FROM #__eventcalendar WHERE seotitle='".$eventseo."'";
180 $database->setQuery($query, '#__', 1, 0);
181 $eventid = $database->loadResult();
184 $_GET['eventid'] = $eventid;
185 $_REQUEST['eventid'] = $eventid;
186 $QUERY_STRING[] = 'eventid='.$eventid;
194 if (isset($parts[2]) && ($parts[2] != '')) { // URL = ../events/editevent/[$event_seotitle].html
195 $eventseo = preg_replace('/(\.html)$/', '', $parts[2]);
196 if ($eventseo == 'save') {
197 $_GET['task'] = 'save';
198 $_REQUEST['task'] = 'save';
199 $QUERY_STRING[] = 'task=save';
200 } else if ($eventseo == 'cancel') {
201 $_GET['task'] = 'cancel';
202 $_REQUEST['task'] = 'cancel';
203 $QUERY_STRING[] = 'task=cancel';
205 $_GET['task'] = 'editevent';
206 $_REQUEST['task'] = 'editevent';
207 $QUERY_STRING[] = 'task=editevent';
209 $query = "SELECT id FROM #__eventcalendar WHERE seotitle='".$eventseo."'";
210 $database->setQuery($query, '#__', 1, 0);
211 $eventid = $database->loadResult();
214 $_GET['eventid'] = $eventid;
215 $_REQUEST['eventid'] = $eventid;
216 $QUERY_STRING[] = 'eventid='.$eventid;
221 } else { // URL = ../events/editevent/
222 $_GET['task'] = 'editevent';
223 $_REQUEST['task'] = 'editevent';
224 $QUERY_STRING[] = 'task=editevent';
227 default: // URL = ../events/[$catids]/.. [NOTE $catids = '' for all categories]
229 if ($catseo == 'all') {
230 $query = "SELECT id FROM #__categories WHERE section='com_eventcalendar'";
232 $catseo = explode( "+", $parts[1] );
233 if (count($catseo) == 1) {
234 $query = "SELECT id FROM #__categories WHERE seotitle='".$catseo[0]."'";
236 $query = "SELECT id FROM #__categories WHERE seotitle IN (" . implode(",", $catseo) . ")";
239 $database->setQuery($query, '#__');
240 $catid = $database->loadResultArray();
243 $_GET['catid'] = implode("+", $catid);
244 $_REQUEST['catid'] = implode("+", $catid);
245 $QUERY_STRING[] = 'catid='.implode("+", $catid);
247 if (!(isset($parts[2]) && ($parts[2] != ''))) { // URL = ../events/[$catids]/
248 $_GET['task'] = 'catview';
249 $_REQUEST['task'] = 'catview';
250 $QUERY_STRING[] = 'task=catview';
251 } else { // URL = ../events/[$catids]/YYYY/..
252 $_GET['year'] = $parts[2];
253 $_REQUEST['year'] = $parts[2];
254 $QUERY_STRING[] = 'year='.$parts[2];
256 if (isset($parts[3]) && ($parts[3] != '')) {
257 if (strlen($parts[3]) > 2) { // URL = ../events/[$catids]/YYYY/WW.html
258 $week = intval(preg_replace('/(\.html)$/', '', $parts[3]));
259 $_GET['task'] = 'weekview';
260 $_REQUEST['task'] = 'weekview';
261 $QUERY_STRING[] = 'task=weekview';
263 $_GET['week'] = $week;
264 $_REQUEST['week'] = $week;
265 $QUERY_STRING[] = 'week='.$week;
266 } else { // URL = ../events/[$catids]/YYYY/MM/..
267 $_GET['month'] = $parts[3];
268 $_REQUEST['month'] = $parts[3];
269 $QUERY_STRING[] = 'month='.$parts[3];
270 if (isset($parts[4]) && ($parts[4] != '')) { // URL = ../events/[$catids]/YYYY/MM/DD.html
271 $day = intval(preg_replace('/(\.html)$/', '', $parts[4]));
272 $_GET['task'] = 'dayview';
273 $_REQUEST['task'] = 'dayview';
274 $QUERY_STRING[] = 'task=dayview';
277 $_REQUEST['day'] = $day;
278 $QUERY_STRING[] = 'day='.$day;
279 } else { // URL = ../events/[$catids]/YYYY/MM/
281 $_REQUEST['day'] = '01';
282 $QUERY_STRING[] = 'day=01';
285 } else { // URL = ../events/[$catids]/YYYY/
286 $_GET['task'] = 'monthview';
287 $_REQUEST['task'] = 'monthview';
288 $QUERY_STRING[] = 'task=monthview';
290 $_GET['month'] = '01';
291 $_REQUEST['month'] = '01';
292 $QUERY_STRING[] = 'month=01';
295 $_REQUEST['day'] = '01';
296 $QUERY_STRING[] = 'day=01';
307 $query = "SELECT id FROM #__menu WHERE link='index.php?option=com_eventcalendar' AND published='1'"
308 ."\n AND ((language IS NULL) OR (language LIKE '%$lang%'))";
310 if ($itemsyn) { $_Itemid = $itemsyn; }
311 if (isset($_Itemid) && ($_Itemid > 0)) {
314 $database->setQuery($query, '#__', 1, 0);
315 $Itemid = intval($database->loadResult());
318 $_GET['Itemid'] = $Itemid;
319 $_REQUEST['Itemid'] = $Itemid;
320 $QUERY_STRING[] = 'Itemid='.$Itemid;
323 if (count($QUERY_STRING) > 0) { $qs = implode('&',$QUERY_STRING); }
324 if (trim($link[1]) != '') { $qs .= ($qs == '') ?
$link[1] : '&'.$link[1]; }
326 $_SERVER['QUERY_STRING'] = $qs;
327 $_SERVER['REQUEST_URI'] = ($qs != '') ?
'/index.php?'.$qs : '/index.php';