Category Handling Bugfix [Patch Included]

  • nargin
  • nargin's Avatar Topic Author
  • Offline
  • New Member
  • New Member
2 years 3 months ago #685 by nargin
nargin created the topic: Category Handling Bugfix [Patch Included]

Moving from PHP 5.5 to PHP 5.6 SimpleCalendar started to produce Warning messages in the category list. First I thought this is due to more pedantic error checking in the new PHP version but it turned out these were actual bugs in SimpleCalendar surfacing and correct behaviour is merely luck :unsure: I have fixed to bugs for my website and attached the patch file with the bugfixes. Yet from what I've seen I expect there are more functional bugs and I suggest you check those when you get arround to :) So for now here is what if've fixed.

The Warning:
Notice: Array to string conversion in ...

3 Reasons.

1.) The events model uses the following code to load category data:
575    if ( $app->input->get('catid', '') != '' ) {
576        $categoryArray = array('id' => $app->input->get('catid', ''));
Now 'catid' is an array, yet 'input->get' expects this to be a string ( docs here ) and applies a regex to sanitize the string. Now I don't know why the rest of the code works after the forced cast to string, but the the 'get' method allows to specify that 'catid' is an array so handling is actually correct. This is what I run now:
if ( $app->input->get('catid', '', 'ARRAY') != '' ) {
    $categoryArray = array('id' => $app->input->get('catid', '', 'ARRAY'));

2.) This was OK. Now comes the bad part, which is the PRINT and VCAL button in the category view. This is the original code:
56    echo SCOutput::showIcon('printpreview', JRoute::_(SimpleCalendarHelperRoute::getCategoryRoute($this->app->input->get('catid')) . '&tmpl=component'));
60    echo SCOutput::showIcon('vcal', JRoute::_(SimpleCalendarHelperRoute::getCategoryRoute($this->app->input->get('catid')) . '&tmpl=component&vcal=1'));
I already mentioned the 'input->get('catid')' is incorrect but at least works. Yet here, applying the previous fix breaks SimpleCalendar. I traced this down and realized this: the 'getCategoryRoute' always returns an empty string in your current release, making it obsolete! The reason is this: the 'input->get('catid')' returns a string with the Value "Array" because the catid array is force-casted into a string. Now the 'getCategoryRoute' function casts this string into an int, yielding 0, which is ignored (check your code) and as a result, the function returns the empty string. Applying my fix from (1) actually passes the correct array to the 'getCategoryRoute' function, still the result is incorrect. I did not trace it, but just removing the call to 'getCategoryRoute' alltogether fixes the problem and yields the same behaviour as the current SimpleCalendar release, that is:
56    echo SCOutput::showIcon('printpreview', JRoute::_('&tmpl=component'));
60    echo SCOutput::showIcon('vcal', JRoute::_('&tmpl=component&vcal=1'));
I know this is nasty, but the behaviour is actually the same. I suggest you check this at some point ;)

3.) The last thing is in the default_list view. Here, getInt is called on catid, which again is an array and fails. Luckily enough the result of that function is never used in the code (so some leftover of old releases...?) so commenting it fixes the problem. Still, i saw some further calls to get catid around that code. While it isn't used on my website right now, I highly doubt the current implementation is correct and I suggest you check that as well. This is the code I commented:
59    $catid_var = JRequest::getInt('catid');

I attached the patchfile. This was checked with SimpleCalendar 3.0.10, Joomla 3.4.5, PHP 5.6.13. I suggest you verify all that category handling code when you get around it, this just fixes my use case.

On a side note, the same warning was reported in this forum two years ago . While I don't know if it's the same issue, my problem stems from the exact same line. Your comment was that since the error is not generated from a SimpleCalendar source file, it's probably unrelated. This was not the case here. While the error was generated by a Joomla helper class, it was due incorrect data fed by SimplCalendar. I would recommand you check that next time someone reports problems expierenced when using SimpleCalendar :cheer:

I hope my explanations helped.


com_simplecalendar/site/models/events.php                  | 4 ++--
 com_simplecalendar/site/views/events/tmpl/default.php      | 6 +++---
 com_simplecalendar/site/views/events/tmpl/default_list.php | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/com_simplecalendar/site/models/events.php b/com_simplecalendar/site/models/events.php
index 725d65e..84b1239 100644
--- a/com_simplecalendar/site/models/events.php
+++ b/com_simplecalendar/site/models/events.php
@@ -572,8 +572,8 @@ class SimpleCalendarModelEvents extends JModelList
 			$options = array();
 // 			$options['countItems'] = $params->get('show_cat_items', 1) || $params->get('show_empty_categories', 0);
 			$categoriesObject = JCategories::getInstance('SimpleCalendar', $options);
-			if ( $app->input->get('catid', '') != '' ) {
-				$categoryArray = array('id' => $app->input->get('catid', ''));
+			if ( $app->input->get('catid', '', 'ARRAY') != '' ) {
+				$categoryArray = array('id' => $app->input->get('catid', '', 'ARRAY'));
 			} else {
 				$categoryArray = $this->getState('', 'root');
diff --git a/com_simplecalendar/site/views/events/tmpl/default.php b/com_simplecalendar/site/views/events/tmpl/default.php
index 635cf1b..5d73b01 100644
--- a/com_simplecalendar/site/views/events/tmpl/default.php
+++ b/com_simplecalendar/site/views/events/tmpl/default.php
@@ -50,13 +50,13 @@ JHtml::_('behavior.framework');
 <span class="buttons"><?php 
 if ( $this->app->input->get('tmpl') != 'component')
-	if ( $this->params->get('show_print_icon_list', '1') ) 
+	if ( $this->params->get('show_print_icon_list', '1') )
-		echo SCOutput::showIcon('printpreview', JRoute::_(SimpleCalendarHelperRoute::getCategoryRoute($this->app->input->get('catid')) . '&tmpl=component'));
+		echo SCOutput::showIcon('printpreview', JRoute::_('&tmpl=component'));
 	if ( $this->params->get('show_vcal_icon_list', '1') )
-		echo SCOutput::showIcon('vcal', JRoute::_(SimpleCalendarHelperRoute::getCategoryRoute($this->app->input->get('catid')) . '&tmpl=component&vcal=1'));
+		echo SCOutput::showIcon('vcal', JRoute::_('&tmpl=component&vcal=1'));
diff --git a/com_simplecalendar/site/views/events/tmpl/default_list.php b/com_simplecalendar/site/views/events/tmpl/default_list.php
index 8e60a2c..c9f2436 100644
--- a/com_simplecalendar/site/views/events/tmpl/default_list.php
+++ b/com_simplecalendar/site/views/events/tmpl/default_list.php
@@ -55,7 +55,7 @@ $colspan = sizeof($this->columns);
 <div class="events_container">
-$catid_var = JRequest::getInt('catid');
+//$catid_var = JRequest::getInt('catid');
 $catid_param = $this->params->get('catid');
@@ -181,4 +181,4 @@ foreach ($this->items as $item):
 <?php endif; ?>
 <?php echo '' // $html . "\n" . $footer . "\n" . $body; ?>
\ No newline at end of file

Please Log in or Create an account to join the conversation.

Time to create page: 0.398 seconds
Powered by Kunena Forum