Problem with NP_Ordered on Nucleus 3.65 [fixed]

Found something that doesn't work as expected? Encountered PHP errors? Submit your bug reports here!
User avatar
dis
Posts: 209
Joined: Mon Aug 19, 2002 3:56 am

Problem with NP_Ordered on Nucleus 3.65 [fixed]

Postby dis » Fri Dec 27, 2013 7:00 am

Just ran into the dreaded PHP5/Nucleus 3.65 roadblock. Upgraded my nucleus install from 3.64 to 3.65, added the patches mentioned in other threads, disabled a few plugins which were causing the site to choke, and now have things mostly sorta-kinda running again.

I would however really like to be able to re-enable NP__Ordered again since it was kind of essential for the way I was ordering posts on my site. When it's enabled, the blog loads halfway and the rest of the page is empty - stops after the header banner part, never gets to the content body/items part.

The only clue I have from my server logs so far is the following:

Code: Select all

apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 804


line 804 in NP_Ordered is:

Code: Select all

$manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));


The full context for that part of the plugin is:

Code: Select all

   function _preBlogContent($type, &$blog) {
      global $manager;
      $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));


I am running PHP 5.5.3 and MySQL 5.5.34.

I have read elsewhere on the forum that ftruscot is busy and not around much nowadays so I am just posting this in the hopes that someone might be able to help figure this one out. I can do small tweaks but unfortunately this one is above my head :)

Mods, I wasn't sure whether to put this in bugs (since it's about 3.65 and the new php) or in plugins (since it's about NP_Ordered) so feel free to move the post to wherever you feel it best suits.

Thanks very much in advance to anyone who may be able to help!
Last edited by dis on Mon Dec 30, 2013 12:11 am, edited 1 time in total.
User avatar
slightlysome
Posts: 213
Joined: Thu Feb 24, 2011 1:33 am
Contact:

Postby slightlysome » Sat Dec 28, 2013 6:55 am

Try to change

Code: Select all

$manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));

to

Code: Select all

$data = array('blog' => &$blog, 'type' => $type);
$manager->notify('PreBlogContent', $data);

This should hopefully fix the PHP error.
- Leo -
LMNucleus CMS home page: nucleus.slightlysome.net
My Nucleus powered blogs: www.slightlysome.net - www.tswtraveler.com
My Nucleus plugins.
User avatar
dis
Posts: 209
Joined: Mon Aug 19, 2002 3:56 am

Postby dis » Sat Dec 28, 2013 9:31 pm

Thanks very much, slightlysome!

That got it working to the point where I was actually able to install/load the plugin without the admin panel going sideways on me.

Sadly the blog is still not loading. It stops after the header banner and before any of the content can show up. Syslog now shows a new error message, similar to the first:

Code: Select all

apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 993


Line 993 is as follows:

Code: Select all

$manager->notify('PreDateHead',array('blog' => &$b, 'timestamp' => $timestamp));


The full context for this segment is:

Code: Select all

// add date header if needed
         if ($dateheads) {
            $new_date = date('dFY',$item->timestamp);
            if ($new_date != $old_date) {
               // unless this is the first time, write date footer
               $timestamp = $item->timestamp;
               if ($old_date != 0) {
                  $oldTS = strtotime($old_date);
                  $manager->notify('PreDateFoot',array('blog' => &$b, 'timestamp' => $oldTS));
                  $tmp_footer = strftime($template['DATE_FOOTER'], $oldTS);
                  $parser->parse($tmp_footer);
                  $manager->notify('PostDateFoot',array('blog' => &$b, 'timestamp' => $oldTS));
               }
               $manager->notify('PreDateHead',array('blog' => &$b, 'timestamp' => $timestamp));
               // note, to use templatvars in the dateheader, the %-characters need to be doubled in
               // order to be preserved by strftime
               $tmp_header = strftime($template['DATE_HEADER'],$timestamp);
               $parser->parse($tmp_header);
               $manager->notify('PostDateHead',array('blog' => &$b, 'timestamp' => $timestamp));
            }
            $old_date = $new_date;
         }


I'm guessing the fix will be something similar to what you suggested for the first error but unfortunately I don't know enough to guess it for myself :( Line 993 is near the end of the plugin code so I'm hoping there won't be any or too many more of these errors!

If you have any more suggestions, I would be most grateful for any help you can give. Thanks very much!
Last edited by dis on Sat Dec 28, 2013 9:40 pm, edited 1 time in total.
User avatar
dis
Posts: 209
Joined: Mon Aug 19, 2002 3:56 am

Postby dis » Sat Dec 28, 2013 9:39 pm

ETA:

Just found this http://www.php.net/references.pass when trying to research the error. The note at the top of the article says:

As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);. And as of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error.


There are also examples further down on the page, including one which is marked "Produces fatal error since PHP 5.0.5".

I don't know if any of it is relevant to the problem here but I thought I would just add it to this thread for reference just in case.
User avatar
slightlysome
Posts: 213
Joined: Thu Feb 24, 2011 1:33 am
Contact:

Postby slightlysome » Sat Dec 28, 2013 10:21 pm

dis wrote:Sadly the blog is still not loading. It stops after the header banner and before any of the content can show up. Syslog now shows a new error message, similar to the first:


Try to change the segment to:

Code: Select all

// add date header if needed
         if ($dateheads) {
            $new_date = date('dFY',$item->timestamp);
            if ($new_date != $old_date) {
               // unless this is the first time, write date footer
               $timestamp = $item->timestamp;
               if ($old_date != 0) {
                  $oldTS = strtotime($old_date);
                  $eventparam = array('blog' => &$b, 'timestamp' => $oldTS);
                  $manager->notify('PreDateFoot', $eventparam);
                  $tmp_footer = strftime($template['DATE_FOOTER'], $oldTS);
                  $parser->parse($tmp_footer);
                  $manager->notify('PostDateFoot', $eventparam);
               }
               $eventparam = array('blog' => &$b, 'timestamp' => $timestamp);
               $manager->notify('PreDateHead', $eventparam);
               // note, to use templatvars in the dateheader, the %-characters need to be doubled in
               // order to be preserved by strftime
               $tmp_header = strftime($template['DATE_HEADER'],$timestamp);
               $parser->parse($tmp_header);
               $manager->notify('PostDateHead', $eventparam);
            }
            $old_date = $new_date;
         }
- Leo -

LMNucleus CMS home page: nucleus.slightlysome.net

My Nucleus powered blogs: www.slightlysome.net - www.tswtraveler.com

My Nucleus plugins.
User avatar
dis
Posts: 209
Joined: Mon Aug 19, 2002 3:56 am

Postby dis » Sat Dec 28, 2013 10:56 pm

w00t! Houston, we have progress! Thanks again, slightlysome! :D

I ran into half a dozen more of the same errors. I think I kind of got the idea of how you changed it now so I tried to copy what you did with each new variable. Most of the page is now loading, yay!

I'm now stuck on an error that I haven't been able to fix yet because the code is a little bit different from your base example and my tweak didn't work perfectly for it.

Here's the latest part that's erroring out:

Code: Select all

$manager->notify(
            'PreCategoryListItem',
            array(
               'listitem' => &$data
            )
         );


So I tried to change it like I did all the others, following your example:

Code: Select all

      $data = array('listitem' => &$data, 'type' => $type);
         $manager->notify('PreCategoryListItem', $data);


But I'm continuing to get the same "apache2: PHP Fatal error: Cannot pass parameter 2 by reference in blah on line 1143" error.

For the record, these are all the lines that have been fixed so far:

Code: Select all

apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 1007
apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 1007
apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 1008
apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 1014
apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 1027
apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 1027
apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 1033
apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 815
apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 1143
apache2: PHP Fatal error:  Cannot pass parameter 2 by reference in /var/www/html/user/nucleus/plugins/NP_Ordered.php on line 1143


As you can see, we are now currently stuck on line 1143 :? :D
User avatar
dis
Posts: 209
Joined: Mon Aug 19, 2002 3:56 am

Postby dis » Sat Dec 28, 2013 11:43 pm

Hmm, possibly I messed up in my attempt to fix the errors just before this one. The code in those was a bit more complicated and it may have required a different fix on account of that timestamp part.

This is the section below, with the original code commented out and my fix attempt added.

Code: Select all

      $numrows = mysql_num_rows($items);

      // add another date footer if there was at least one item
      if (($numrows > 0) && $dateheads) {
// commenting out the original problem code
         //$manager->notify('PreDateFoot',array('blog' => &$b, 'timestamp' => strtotime($old_date)));
// another fix attempt this one more complicated but try same thing
         $data = array('blog' => &$blog, 'type' => $type);
         $manager->notify('PreDateFoot', $data);
// end fix attempt
         $parser->parse($template['DATE_FOOTER']);
         // $manager->notify('PostDateFoot',array('blog' => &$b, 'timestamp' => strtotime($old_date)));
         // and fix attempt again
         $data = array('blog' => &$blog, 'type' => $type);
         $manager->notify('PostDateFoot', $data);
         // end fix attempt
      }

      mysql_free_result($items);   // free memory

      return $numrows;


This was the error/fix that occurred just before the current 1143 line, around lines 1027 - 1033. The other errors before it were the simpler kind that the basic fix seemed to work fine for.
User avatar
dis
Posts: 209
Joined: Mon Aug 19, 2002 3:56 am

Postby dis » Sun Dec 29, 2013 12:05 am

Changed the above as follows:

Code: Select all

      $numrows = mysql_num_rows($items);

      // add another date footer if there was at least one item
      if (($numrows > 0) && $dateheads) {
         // original code commented out
         //$manager->notify('PreDateFoot',array('blog' => &$b, 'timestamp' => strtotime($old_date)));
         // another fix attempt this one following slightlysomes second example
            $eventparam = array('blog' => &$b, 'timestamp' => $olddate);
               $manager->notify('PreDateFoot', $eventparam);
         // end fix attempt
         $parser->parse($template['DATE_FOOTER']);
          // original code commented out
          // $manager->notify('PostDateFoot',array('blog' => &$b, 'timestamp' => strtotime($old_date)));
         // and fix attempt again
            $eventparam = array('blog' => &$b, 'timestamp' => $olddate);
               $manager->notify('PostDateFoot', $eventparam);
         // end fix attempt
      }

      mysql_free_result($items);   // free memory

      return $numrows;

   }


And now I no longer get any error messages at all, but the categories on the sidebar, which use NP_Ordered for sorting, are not showing up. Everything else seems to be working now though! :)

There's probably something extra I need to do with the timestamp part, but no clue how to do it :lol: Going to go back and look over all the changes so far and see if I've missed anything...

ETA: i don't see a way to attach files on the forum here, so i've uploaded a copy of the current version of the plugin, with all the fixes so far, here.

The fixes start around line 804 and go on till somewhere around line 1150. You can spot them fairly easily by scanning for the commented sections, which mediafire displays in turquoise font. I end all the fixed sections with

Code: Select all

// end fix attempt
so you can also search for that if you want to find them quickly.

If we manage to get it completely fixed I'll upload the final version to the NP_Ordered plugin's dedicated thread for future reference.

ETA2: found what i think were a couple of errors on my part. edited and re-uploaded the NP_Ordered.php file. the download link remains the same. I'll remove it from mediafire later and leave the finished version on the NP_Ordered thread instead once (if) it's finalized.
Last edited by dis on Sun Jul 13, 2014 2:41 am, edited 1 time in total.
User avatar
slightlysome
Posts: 213
Joined: Thu Feb 24, 2011 1:33 am
Contact:

Postby slightlysome » Sun Dec 29, 2013 4:24 am

I have gone through the file you uploaded. Here is a version where all notify errors should be fixed.

Update: Link removed as you should get the updated plugin from the NP_Ordered plugin page.
Last edited by slightlysome on Sat Apr 19, 2014 6:33 pm, edited 1 time in total.
- Leo -

LMNucleus CMS home page: nucleus.slightlysome.net

My Nucleus powered blogs: www.slightlysome.net - www.tswtraveler.com

My Nucleus plugins.
User avatar
dis
Posts: 209
Joined: Mon Aug 19, 2002 3:56 am

Postby dis » Mon Dec 30, 2013 12:11 am

W00t, it worked! Everything is loading perfectly now! Thank you so much! :D i have uploaded the updated NP_Ordered code to the NP_Ordered thread in the plugins subforum for future reference as well.

Return to “Bug Reports & Feature Requests”