• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to update this statement to PHP 5.4

#1
I am working on getting XenTrader up and running again on my forum. Slavik is very busy lately and he provided me with the changes I had to make for the

$anchor->nodeValue =
But, now I am getting errors on this code:

$this->standardizeViewingUserReference($user);
I assume it has to be updated for PHP5.4

Can anyone help?

For the record this is the error I am getting:
Argument 1 passed to XenTrader_Model_Feedback::standardizeViewingUserReference() must be of the type array, boolean given, called in /home/oakleyfo/public_html/library/XenTrader/Model/Feedback.php on line 25 and defined
 
#3
I believe it is this:
public function hasPermission($permission = '', $user = null)

{
if (is_numeric($user))
{
$user = $this->getModelFromCache('XenForo_Model_User')->getUserById(
$user, array('join' => XenForo_Model_User::FETCH_USER_PERMISSIONS)
);

if (!$user)
return false;
}

$this->standardizeViewingUserReference($user);
 

Jeremy

Well-known member
#6
Do you have a full stack trace for when you are getting this error? It seems like at some point, XenTrader_Model_Feedback::hasPermission is being called where $user is being passed in as true. Try changing line 21 to this:

PHP:
if(!$user || is_bool($user))
 
#7
I added that in, but still get the error. Here is the full error:

Server Error

Argument 1 passed to XenTrader_Model_Feedback::standardizeViewingUserReference() must be of the type array, boolean given, called in /home/oakleyfo/public_html/library/XenTrader/Model/Feedback.php on line 25 and defined
  1. XenForo_Application::handlePhpError() in XenTrader/Model/Feedback.php at line 51
  2. XenTrader_Model_Feedback->standardizeViewingUserReference() in XenTrader/Model/Feedback.php at line 25
  3. XenTrader_Model_Feedback->hasPermission() in XenTrader/ControllerPublic/Abstract.php at line 12
  4. XenTrader_ControllerPublic_Abstract->_assertHasPermission() in XenTrader/ControllerPublic/Index.php at line 171
  5. XenTrader_ControllerPublic_Index->actionLeaveFeedback() in XenForo/FrontController.php at line 310
  6. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
  7. XenForo_FrontController->run() in /home/oakleyfo/public_html/index.php at line 13
Full Stack Trace
#0 /home/oakleyfo/public_html/library/XenTrader/Model/Feedback.php(51): XenForo_Application::handlePhpError(4096, 'Argument 1 pass...', '/home/oakleyfo/...', 51, Array)
#1 /home/oakleyfo/public_html/library/XenTrader/Model/Feedback.php(25): XenTrader_Model_Feedback->standardizeViewingUserReference(false)
#2 /home/oakleyfo/public_html/library/XenTrader/ControllerPublic/Abstract.php(12): XenTrader_Model_Feedback->hasPermission('receiveFeedback', false)
#3 /home/oakleyfo/public_html/library/XenTrader/ControllerPublic/Index.php(171): XenTrader_ControllerPublic_Abstract->_assertHasPermission('receiveFeedback', false)
#4 /home/oakleyfo/public_html/library/XenForo/FrontController.php(310): XenTrader_ControllerPublic_Index->actionLeaveFeedback()
#5 /home/oakleyfo/public_html/library/XenForo/FrontController.php(132): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#6 /home/oakleyfo/public_html/index.php(13): XenForo_FrontController->run()

#7 {main}
FYI

Right now(after upgrading to PHP 5.4), the XenTrader tab doesn't show up in the Navigation bar, the feedback ratings don't show up in Users profiles or post profiles. So their is no way for them to leave or view feedback. I added the tab /Xentrader.php manually, but there is no way to search members either.

The error above is what I get when I navigate to /Xentrader/leave-feedback
 

Jeremy

Well-known member
#8
#1 - 3 are showing its having false passed in versus a valid user or numeric.

Code:
if(!$user || is_bool($user))
should have caught that.

Can you post your full XenTrader_Model_Feedback::hasPermission function?
 
#9
Here is the entire function:

Code:
    public function hasPermission($permission = '', $user = null)
    {
        if (is_numeric($user))
        {
            $user = $this->getModelFromCache('XenForo_Model_User')->getUserById(
                $user, array('join' => XenForo_Model_User::FETCH_USER_PERMISSIONS)
            );
 
    if(!$user || is_bool($user))
                return false;
        }
 
        $this->standardizeViewingUserReference($user);
 
        if (is_array($user['permissions']) && XenForo_Permission::hasPermission($user['permissions'], 'xentrader', $permission))
        {
            $userModel = $this->getModelFromCache('XenTrader_Model_User');
 
            if ($user2 = $userModel->getUserById($user['user_id']))
                $user = array_merge($user, $user2);
 
            if ($permission == 'leaveFeedback' && $userModel->getUserType($user) == XenTrader_Model_User::TRADER_TYPE_NEW)
            {
                $numFeedback = $this->countFeedback(array(
                    'newer_than' => XenForo_Application::$time - 86400,
                    'from_user' => $user['user_id'],
                ));
 
                if ($numFeedback >= XenForo_Application::get('options')->xentraderNewTraderDailySubmissions)
                    return false;
            }
 
            return true;
        }
 
        return false;
    }
 

Jeremy

Well-known member
#10
Change the first few lines too...
PHP:
        if (is_numeric($user))
         {
             $user = $this->getModelFromCache('XenForo_Model_User')->getUserById(
                 $user, array('join' => XenForo_Model_User::FETCH_USER_PERMISSIONS)
             );
         }

     if(!$user || is_bool($user))
                 return false;
 
#11
That caused permission errors. Per slovaks instructions:


in the model/feedback php

find

public function standardizeViewingUserReference(array &$user = null)

replace with

public function standardizeViewingUserReference(&$user = null)
But now I have a new error:

Code:
Argument 1 passed to XenForo_Model::standardizeViewingUserReference() must be of the type array, boolean given, called in /home/oakleyfo/public_html/library/XenTrader/Model/Feedback.php on line 53 and defined
 
XenForo_Application::handlePhpError() in XenForo/Model.php at line 511
XenForo_Model->standardizeViewingUserReference() in XenTrader/Model/Feedback.php at line 53
XenTrader_Model_Feedback->standardizeViewingUserReference() in XenTrader/Model/Feedback.php at line 25
XenTrader_Model_Feedback->hasPermission() in XenTrader/ControllerPublic/Abstract.php at line 12
XenTrader_ControllerPublic_Abstract->_assertHasPermission() in XenTrader/ControllerPublic/Index.php at line 171
XenTrader_ControllerPublic_Index->actionLeaveFeedback() in XenForo/FrontController.php at line 310
XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
XenForo_FrontController->run() in /home/oakleyfo/public_html/index.php at line 13
 

Jeremy

Well-known member
#12
His fix is wrong. XenForo_Model::standardizeViewingUserReference() requires an array passed by reference, so changing XenTrader_Model_Feedback::standardizeViewingUserReference() to use one is incorrect. It needs to remain array &user = null.
 

tyteen4a03

Well-known member
#13
What happens when you add an else clause to the first condition?

Code:
        if (is_numeric($user))
        {
            $user = $this->getModelFromCache('XenForo_Model_User')->getUserById(
                $user, array('join' => XenForo_Model_User::FETCH_USER_PERMISSIONS)
            );
 
            if (!$user)
                return false;
        } else {
            die(var_dump($user));
        }
 

tyteen4a03

Well-known member
#15
The whole website just says "Null" when I put that in.
The problem comes from XenTrader_ControllerPublic_Abstract:L7. It doesn't pass a $user parameter, causing this error.

Change the whole _preDispatch function into this:

Code:
    protected function _preDispatch($action)
    {
        $this->_assertHasPermission('viewFeedback', XenForo_Visitor::getInstance()->toArray());
    }
 

Jeremy

Well-known member
#18
I'm still on a phone but the call the $this->hasPermission seemed to be missing the $user array in most parts in ControllerPublic_Index. Then again, I could be misremembering.
 
#19
The problem comes from XenTrader_ControllerPublic_Abstract:L7. It doesn't pass a $user parameter, causing this error.

Change the whole _preDispatch function into this:
Added this, then added the previous fix but still got NULL.