On branch master
[event_calendar.git] / seopro.com_eventcalendar.php
blobb8640b3afe06de3c1d28e4d2dc2f3a86c56a03bc
1 <?php
3 /*
4 * Event Calendar for Elxis CMS 2008.x and 2009.x
6 * SEO Pro Handler
8 * @version 1.1
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
13 * @link
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')) {
20 global $_VERSION;
21 if ($_VERSION->RELEASE > 2008) {
22 define('EVCALBASE', 'events');
23 } else {
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 );
38 $vars = array();
39 $vars['option'] = 'com_eventcalendar';
40 $vars['task'] = '';
41 $vars['catid'] = '';
42 $vars['eventid'] = '';
43 $vars['year'] = '';
44 $vars['month'] = '';
45 $vars['week'] = '';
46 $vars['day'] = '';
47 $vars['Itemid'] = '';
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);
55 $x = strtolower($x);
56 $vars[$x] = $y;
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();
66 } else {
67 $eventseo = '';
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
78 $catid = '';
80 $query = "SELECT seotitle FROM #__categories WHERE section='com_eventcalendar'";
81 if (is_array( $catid )) {
82 $query .= "\n AND id IN (" . implode( ",", $catid ) . ")";
83 } else if ($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']) {
91 case 'save':
92 return $mosConfig_live_site.'/'.EVCALBASE.'/editevent/save.html';
93 break;
94 case 'cancel':
95 return $mosConfig_live_site.'/'.EVCALBASE.'/editevent/cancel.html';
96 break;
97 case 'editevent':
98 return $mosConfig_live_site.'/'.EVCALBASE.'/editevent/'.( ($eventseo)?($eventseo.'.html'):'' );
99 break;
100 case 'eventview':
101 return $mosConfig_live_site.'/'.EVCALBASE.'/'.$eventseo.'.html';
102 break;
103 case 'monthview':
104 return $mosConfig_live_site.'/'.EVCALBASE.'/'.(($catid)?implode("+", $catseo):'all').'/'.$vars['year'].'/'.$vars['month'].'/';
105 break;
106 case 'weekview':
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';
109 break;
110 case 'dayview':
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';
113 break;
114 case 'catview':
115 return $mosConfig_live_site.'/'.EVCALBASE.'/'.(($catid)?implode("+", $catseo):'all').'/';
116 break;
117 case 'syndication':
118 return $mosConfig_live_site.'/'.EVCALBASE.'/syndication.html';
119 break;
120 default:
121 return $mosConfig_live_site.'/'.EVCALBASE.'/';
122 break;
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('/(&amp;)/', '&', $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
142 $_GET['catid'] = '';
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());
166 } else {
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';
174 } else {
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();
183 if ($eventid) {
184 $_GET['eventid'] = $eventid;
185 $_REQUEST['eventid'] = $eventid;
186 $QUERY_STRING[] = 'eventid='.$eventid;
187 } else {
188 pageNotFound();
191 } else {
192 switch ($parts[1]) {
193 case 'editevent':
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';
204 } else {
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();
213 if ($eventid) {
214 $_GET['eventid'] = $eventid;
215 $_REQUEST['eventid'] = $eventid;
216 $QUERY_STRING[] = 'eventid='.$eventid;
217 } else {
218 pageNotFound();
221 } else { // URL = ../events/editevent/
222 $_GET['task'] = 'editevent';
223 $_REQUEST['task'] = 'editevent';
224 $QUERY_STRING[] = 'task=editevent';
226 break;
227 default: // URL = ../events/[$catids]/.. [NOTE $catids = '' for all categories]
228 $catseo = $parts[1];
229 if ($catseo == 'all') {
230 $query = "SELECT id FROM #__categories WHERE section='com_eventcalendar'";
231 } else {
232 $catseo = explode( "+", $parts[1] );
233 if (count($catseo) == 1) {
234 $query = "SELECT id FROM #__categories WHERE seotitle='".$catseo[0]."'";
235 } else {
236 $query = "SELECT id FROM #__categories WHERE seotitle IN (" . implode(",", $catseo) . ")";
239 $database->setQuery($query, '#__');
240 $catid = $database->loadResultArray();
242 if ($catid) {
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';
276 $_GET['day'] = $day;
277 $_REQUEST['day'] = $day;
278 $QUERY_STRING[] = 'day='.$day;
279 } else { // URL = ../events/[$catids]/YYYY/MM/
280 $_GET['day'] = '01';
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';
294 $_GET['day'] = '01';
295 $_REQUEST['day'] = '01';
296 $QUERY_STRING[] = 'day=01';
299 } else {
300 pageNotFound();
302 break;
303 } // close switch
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)) {
312 $Itemid = $_Itemid;
313 } else {
314 $database->setQuery($query, '#__', 1, 0);
315 $Itemid = intval($database->loadResult());
318 $_GET['Itemid'] = $Itemid;
319 $_REQUEST['Itemid'] = $Itemid;
320 $QUERY_STRING[] = 'Itemid='.$Itemid;
322 $qs = '';
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';