PageRenderTime 58ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_jevents/jevents.php

https://bitbucket.org/kraymitchell/saiu
PHP | 250 lines | 151 code | 28 blank | 71 comment | 51 complexity | 6f4c201e027981ed7ad6ba7833f81b4e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * JEvents Component for Joomla 1.5.x
  4. *
  5. * @version $Id: jevents.php 3551 2012-04-20 09:41:37Z geraintedwards $
  6. * @package JEvents
  7. * @copyright Copyright (C) 2008-2009 GWE Systems Ltd
  8. * @license GNU/GPLv2, see http://www.gnu.org/licenses/gpl-2.0.html
  9. * @link http://www.jevents.net
  10. */
  11. defined( 'JPATH_BASE' ) or die( 'Direct Access to this location is not allowed.' );
  12. jimport('joomla.filesystem.path');
  13. /*
  14. // JevDate test
  15. jimport("joomla.utilities.date");
  16. $date = new JevDate("1.30pm 12 March 2011", new DateTimeZone('America/New_York'));
  17. echo $date->format("Y-m-d H:i:s")."<br/>";
  18. echo "<hr/>";
  19. $date->add(new DateInterval('P1D'));
  20. echo $date->format("Y-m-d H:i:s")."<br/>";
  21. echo "<hr/>";
  22. $date = new JevDate("1.30pm 12 March 2011", new DateTimeZone('UTC'));
  23. echo $date->format("Y-m-d H:i:s")."<br/>";
  24. echo "<hr/>";
  25. $date->add(new DateInterval('P1D'));
  26. echo $date->format("Y-m-d H:i:s")."<br/>";
  27. echo "<hr/>";
  28. $date = new JevDate("1.30pm 12 March 2011", new DateTimeZone('America/New_York'));
  29. echo $date->format("Y-m-d H:i:s")."<br/>";
  30. echo "<hr/>";
  31. $date->modify("+1 day");
  32. echo $date->format("Y-m-d H:i:s")."<br/>";
  33. echo "<hr/>";
  34. */
  35. // For development performance testing only
  36. /*
  37. $db =& JFactory::getDBO();
  38. $db->setQuery("SET SESSION query_cache_type = OFF");
  39. $db->query();
  40. $cfg = & JEVConfig::getInstance();
  41. $cfg->set('jev_debug', 1);
  42. */
  43. include_once(JPATH_COMPONENT.DS."jevents.defines.php");
  44. $isMobile = false;
  45. jimport("joomla.environment.browser");
  46. $browser = JBrowser::getInstance();
  47. $registry =& JRegistry::getInstance("jevents");
  48. // In Joomla 1.6 JComponentHelper::getParams(JEV_COM_COMPONENT) is a clone so the menu params do not propagate so we force this here!
  49. if (JVersion::isCompatible("1.6.0")){
  50. $newparams = JFactory::getApplication('site')->getParams();
  51. // Because the application sets a default page title,
  52. // we need to get it from the menu item itself
  53. $menu = JFactory::getApplication()->getMenu()->getActive();
  54. if ($menu) {
  55. $newparams->def('page_heading', $newparams->get('page_title', $menu->title));
  56. }
  57. else {
  58. $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
  59. $newparams->def('page_heading', $params->get('page_title')) ;
  60. }
  61. $component =& JComponentHelper::getComponent(JEV_COM_COMPONENT);
  62. $component->params =& $newparams;
  63. $isMobile = $browser->isMobile();
  64. // Joomla isMobile method doesn't identify all android phones
  65. if (!$isMobile && isset($_SERVER['HTTP_USER_AGENT'])){
  66. if (stripos($_SERVER['HTTP_USER_AGENT'], 'android') >0) {
  67. $isMobile = true;
  68. }
  69. else if (stripos($_SERVER['HTTP_USER_AGENT'], 'iphone')>0 || stripos($_SERVER['HTTP_USER_AGENT'], 'ipod')>0) {
  70. $isMobile = true;
  71. }
  72. }
  73. }
  74. else {
  75. $isMobile = $browser->_mobile;
  76. }
  77. $params =& JComponentHelper::getParams(JEV_COM_COMPONENT);
  78. if ($isMobile || strpos(JFactory::getApplication()->getTemplate(), 'mobile_')===0 || (class_exists("T3Common") && class_exists("T3Parameter") && T3Common::mobile_device_detect()) || JRequest::getVar("jEV","")=="smartphone"){
  79. JRequest::setVar("jevsmartphone",1);
  80. if (JFolder::exists(JEV_VIEWS."/smartphone")){
  81. JRequest::setVar("jEV","smartphone");
  82. }
  83. $params->set('iconicwidth',485);
  84. $params->set('extpluswidth',485);
  85. $params->set('ruthinwidth',485);
  86. }
  87. // See http://www.php.net/manual/en/timezones.php
  88. $tz=$params->get("icaltimezonelive","");
  89. if ($tz!="" && is_callable("date_default_timezone_set")){
  90. $timezone= date_default_timezone_get();
  91. date_default_timezone_set($tz);
  92. $registry->setValue("jevents.timezone",$timezone);
  93. }
  94. if (!JVersion::isCompatible("1.6.0")){
  95. // Multi-category events only supported in Joomla 2.5 + so disable elsewhere
  96. $params->set('multicategory',0);
  97. }
  98. // Must also load backend language files
  99. $lang =& JFactory::getLanguage();
  100. $lang->load(JEV_COM_COMPONENT, JPATH_ADMINISTRATOR);
  101. // Load Site specific language overrides
  102. $lang->load(JEV_COM_COMPONENT, JPATH_THEMES.DS.JFactory::getApplication()->getTemplate());
  103. // disable Zend php4 compatability mode
  104. @ini_set("zend.ze1_compatibility_mode","Off");
  105. // Split task into command and task
  106. $cmd = JRequest::getCmd('task', false);
  107. if (!$cmd || !is_string($cmd) || strpos($cmd, '.') == false) {
  108. $view = JRequest::getCmd('view', false);
  109. $layout = JRequest::getCmd('layout', "show");
  110. if ($view && $layout){
  111. $cmd = $view.'.'.$layout;
  112. }
  113. else $cmd = "month.calendar";
  114. }
  115. if (strpos($cmd, '.') != false) {
  116. // We have a defined controller/task pair -- lets split them out
  117. list($controllerName, $task) = explode('.', $cmd);
  118. // Define the controller name and path
  119. $controllerName = strtolower($controllerName);
  120. $controllerPath = JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php';
  121. //$controllerName = "Front".$controllerName;
  122. // If the controller file path exists, include it ... else lets die with a 500 error
  123. if (file_exists($controllerPath)) {
  124. require_once($controllerPath);
  125. } else {
  126. JFactory::getApplication()->enqueueMessage('Invalid Controller - '.$controllerName );
  127. $cmd = "month.calendar";
  128. list($controllerName, $task) = explode('.', $cmd);
  129. $controllerPath = JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php';
  130. require_once($controllerPath);
  131. }
  132. } else {
  133. // Base controller, just set the task
  134. $controllerName = null;
  135. $task = $cmd;
  136. }
  137. // Make the task available later
  138. JRequest::setVar("jevtask",$cmd);
  139. JRequest::setVar("jevcmd",$cmd);
  140. // Are all Jevents pages apart from crawler, rss and details pages to be redirected for search engines?
  141. if (in_array($cmd, array("year.listevents","month.calendar","week.listevents","day.listevents","cat.listevents","search.form",
  142. "search.results","admin.listevents","jevent.edit","icalevent.edit","icalevent.publish","icalevent.unpublish",
  143. "icalevent.editcopy","icalrepeat.edit","jevent.delete","icalevent.delete","icalrepeat.delete","icalrepeat.deletefuture")))
  144. {
  145. $browser = JBrowser::getInstance();
  146. if ($params->get("redirectrobots", 0) && ($browser->isRobot() || strpos ($browser->getAgentString(), "bingbot")!==false))
  147. {
  148. // redirect to crawler menu item
  149. $Itemid = $params->get("robotmenuitem", 0);
  150. JFactory::getApplication()->redirect(JRoute::_("index.php?option=com_jevents&task=crawler.listevents&Itemid=$Itemid"));
  151. }
  152. }
  153. JPluginHelper::importPlugin("jevents");
  154. // Make sure the view specific language file is loaded
  155. JEV_CommonFunctions::loadJEventsViewLang();
  156. // Set the name for the controller and instantiate it
  157. $controllerClass = ucfirst($controllerName).'Controller';
  158. if (class_exists($controllerClass)) {
  159. $controller = new $controllerClass();
  160. } else {
  161. JFactory::getApplication()->enqueueMessage('Invalid Controller Class - '.$controllerClass );
  162. $cmd = "month.calendar";
  163. list($controllerName, $task) = explode('.', $cmd);
  164. JRequest::setVar("jevtask",$cmd);
  165. JRequest::setVar("jevcmd",$cmd);
  166. $controllerClass = ucfirst($controllerName).'Controller';
  167. $controllerPath = JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php';
  168. require_once($controllerPath);
  169. $controller = new $controllerClass();
  170. }
  171. // create live bookmark if requested
  172. $cfg = & JEVConfig::getInstance();
  173. if ($cfg->get('com_rss_live_bookmarks')) {
  174. $Itemid = JRequest::getInt('Itemid', 0);
  175. $rssmodid = $cfg->get('com_rss_modid', 0);
  176. // do not use JRoute since this creates .rss link which normal sef can't deal with
  177. $rssLink = 'index.php?option='.JEV_COM_COMPONENT.'&amp;task=modlatest.rss&amp;format=feed&amp;type=rss&amp;Itemid='.$Itemid.'&amp;modid='.$rssmodid;
  178. $rssLink = JUri::root().$rssLink;
  179. if (JVersion::isCompatible("1.6.0")){
  180. if (method_exists(JFactory::getDocument(),"addHeadLink")){
  181. $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
  182. JFactory::getDocument()->addHeadLink($rssLink, 'alternate', 'rel', $attribs);
  183. }
  184. }
  185. else {
  186. $rss = '<link href="' .$rssLink .'" rel="alternate" type="application/rss+xml" title="JEvents - RSS 2.0 Feed" />'. "\n";
  187. JFactory::getApplication()->addCustomHeadTag( $rss );
  188. }
  189. $rssLink = 'index.php?option='.JEV_COM_COMPONENT.'&amp;task=modlatest.rss&amp;format=feed&amp;type=atom&amp;Itemid='.$Itemid.'&amp;modid='.$rssmodid;
  190. $rssLink = JUri::root().$rssLink;
  191. //$rssLink = JRoute::_($rssLink);
  192. if (JVersion::isCompatible("1.6.0")){
  193. if (method_exists(JFactory::getDocument(),"addHeadLink")){
  194. $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
  195. JFactory::getDocument()->addHeadLink($rssLink, 'alternate', 'rel', $attribs);
  196. }
  197. }
  198. else {
  199. $rss = '<link href="' .$rssLink .'" rel="alternate" type="application/rss+xml" title="JEvents - Atom Feed" />'. "\n";
  200. JFactory::getApplication()->addCustomHeadTag( $rss );
  201. }
  202. }
  203. // Add reference for constructor in registry - unfortunately there is no add by reference method
  204. // we rely on php efficiency to not create a copy
  205. $registry =& JRegistry::getInstance("jevents");
  206. $registry->setValue("jevents.controller",$controller);
  207. // record what is running - used by the filters
  208. $registry->setValue("jevents.activeprocess","component");
  209. // Stop viewing ALL events - it could take VAST amounts of memory
  210. if ($cfg->get('blockall', 0) && ( JRequest::getInt("limit" , -1) == 0 || JRequest::getInt("limit" , -1) >100 )){
  211. JRequest::setVar("limit",100);
  212. }
  213. // Perform the Request task
  214. $controller->execute($task);
  215. // Must reset the timezone back!!
  216. if ($tz && is_callable("date_default_timezone_set")){
  217. date_default_timezone_set($timezone);
  218. }
  219. // Redirect if set by the controller
  220. $controller->redirect();