PageRenderTime 61ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/content/bot_jcalpro_latest_events.php

https://gitlab.com/endomorphosis/OLAAaction
PHP | 176 lines | 99 code | 13 blank | 64 comment | 15 complexity | de9de9d50a4a3457e6d06288bf869340 MD5 | raw file
  1. <?php
  2. /*
  3. **********************************************
  4. JCal Pro Latest Events Plugin
  5. Copyright (c) 2009 Anything-Digital.com
  6. **********************************************
  7. JCal Pro is a fork of the existing Extcalendar component for Joomla!
  8. (com_extcal_0_9_2_RC4.zip from mamboguru.com).
  9. Extcal (http://sourceforge.net/projects/extcal) was renamed
  10. and adapted to become a Mambo/Joomla! component by
  11. Matthew Friedman, and further modified by David McKinnis
  12. (mamboguru.com) to repair some security holes.
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17. This header must not be removed. Additional contributions/changes
  18. may be added to this header as long as no information is deleted.
  19. **********************************************
  20. * Latest Events Plugin
  21. *
  22. * $Id: bot_jcalpro_latest_events.php 640 2010-05-09 09:55:43Z shumisha $
  23. *
  24. * Plugin for displaying upcoming events in connection with the JCal Pro
  25. * component. The component must be installed before this module will work.
  26. **********************************************
  27. Get the latest version of JCal Pro at:
  28. http://dev.anything-digital.com//
  29. **********************************************
  30. */
  31. defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );
  32. $mainframe->registerEvent( 'onPrepareContent', 'plgJCalLatest' );
  33. function plgJCalLatest( &$rowContent, &$params, $page=0 ) {
  34. // save content item params
  35. $contentParams = $params;
  36. // get plugin params
  37. $plugin =& JPluginHelper::getPlugin('content', 'bot_jcalpro_latest_events');
  38. $matches = array();
  39. // regexp to catch plugin requests
  40. $regExp = "#{jcal_latest\s*(.*)}#Us";
  41. $preV21RegExp = "#{jcal_latest}([\d,?]*){/jcal_latest}#s";
  42. // Get Plugin info
  43. // try old style, pre-version 2.1 syntax for calling plugin : {jcal_latest}cat1,cat2,cat3{/jcal_latest}
  44. if (preg_match_all( $preV21RegExp, $rowContent->text, $matches, PREG_SET_ORDER) > 0) {
  45. foreach( $matches as $match) {
  46. $html = '';
  47. // init params from plugin
  48. $params = new JParameter($plugin->params);
  49. if( is_readable(JPATH_ROOT. DS. 'components'.DS.'com_jcalpro'.DS.'include'.DS.'latest.inc.php') ) {
  50. ob_start();
  51. $params->set('categories',$match[1]);
  52. include( JPATH_ROOT. DS. 'components'.DS.'com_jcalpro'.DS.'include'.DS.'latest.inc.php' );
  53. $html = ob_get_contents();
  54. ob_end_clean();
  55. }
  56. $rowContent->text = str_replace( $match[0], $html , $rowContent->text );
  57. }
  58. } else {
  59. // new syntax as of Jcal 2.1 {jcal_latest cat=n show_description=yes ...}
  60. if (preg_match_all( $regExp, $rowContent->text, $matches, PREG_SET_ORDER) > 0) {
  61. foreach( $matches as $match) {
  62. // init params from plugin
  63. $params = new JParameter($plugin->params);
  64. // extract parameters passed as attributes
  65. $attribs = jclGetPluginAttributes( $match[1]);
  66. // set them up
  67. jclSetPluginAttributes( $params, $attribs);
  68. // get output of module
  69. $html = '';
  70. if( is_readable(JPATH_ROOT. DS. 'components'.DS.'com_jcalpro'.DS.'include'.DS.'latest.inc.php') ) {
  71. ob_start();
  72. include( JPATH_ROOT. DS. 'components'.DS.'com_jcalpro'.DS.'include'.DS.'latest.inc.php' );
  73. $html = ob_get_contents();
  74. ob_end_clean();
  75. }
  76. $rowContent->text = str_replace( $match[0], $html , $rowContent->text );
  77. }
  78. }
  79. }
  80. //restore content item params
  81. $params = $contentParams;
  82. }
  83. /**
  84. * Extract parameters from content text {jcal_latest} entry
  85. *
  86. * @param $params the raw parameters string, as extracted by regexp
  87. * @return array individual parameters as $key => $value
  88. */
  89. function jclGetPluginAttributes( $params) {
  90. // attributes allowed as param of plugin call
  91. $paramList = array( 'cat', 'cal', 'sort', 'direction', 'max_upcoming', 'max_recent', 'show_description', 'show_readmore', 'eventid', 'show_category', 'show_calendar');
  92. // output
  93. $attribs = array();
  94. // get individual params
  95. $rawAttribs = explode( ' ', trim($params));
  96. if (!empty( $rawAttribs)) {
  97. foreach( $rawAttribs as $rawAttrib) {
  98. $attrib = array();
  99. parse_str( $rawAttrib, $attrib);
  100. if (!empty( $attrib)) {
  101. foreach( $attrib as $key => $value) {
  102. if (in_array( $key, $paramList, true)) {
  103. // this is a valid attrib, store it in output
  104. $attribs[$key] = trim(str_replace(chr(0xc2).chr(0xa0), '', $value));
  105. }
  106. }
  107. }
  108. }
  109. }
  110. return $attribs;
  111. }
  112. /**
  113. * Set plugin parameters, doing a bit of renaming as we go
  114. *
  115. * @param $params the plugin parameter structure, to be filled with parameters
  116. * @param $attribs arra : the parameters values as extracted by jclGetPluginAttributes
  117. * @return none
  118. */
  119. function jclSetPluginAttributes( & $params, $attribs) {
  120. // check params
  121. if (empty( $attribs) || empty( $params)) {
  122. return;
  123. }
  124. // now set attributes
  125. foreach( $attribs as $key => $value) {
  126. switch ($key) {
  127. case 'cat':
  128. $params->set( 'categories', $value);
  129. break;
  130. case 'cal':
  131. $params->set( 'calendars_list', $value);
  132. break;
  133. case 'eventid':
  134. $params->set( 'events_list', $value);
  135. break;
  136. case 'max_upcoming':
  137. $params->set( 'number_of_events_to_list_upcoming', intval( $value));
  138. break;
  139. case 'max_recent' :
  140. $params->set( 'number_of_events_to_list_recent', intval( $value));
  141. break;
  142. case 'show_description' :
  143. $params->set( 'show_description', $value == 'yes' ? 1 : 0);
  144. break;
  145. case 'show_readmore' :
  146. $params->set( 'show_readmore', $value == 'yes' ? 1 : 0);
  147. break;
  148. case 'show_calendar' :
  149. $params->set( 'show_calendar', $value == 'yes' ? 1 : 0);
  150. break;
  151. case 'show_category' :
  152. $params->set( 'show_category', $value == 'yes' ? 1 : 0);
  153. break;
  154. default:
  155. $params->set( $key, $value);
  156. break;
  157. }
  158. }
  159. }