Cannot load class using XFCP

I have created a listener with the following code:
if ($class == 'XenForo_Visitor')
{
$extend[] = 'AvatarGallery_Visitor';
}

...the new class:
class AvatarGallery_Visitor extends XFCP_AvatarGallery_Visitor
--

However, I get this error:

An exception occurred: Cannot load class using XFCP. Load the class using the correct loader first. in ......library/XenForo/Autoloader.php on line 108
---
what is wrong here?
 
In your listener function did you have the & before the $extend paramater?

PHP:
public function listen($class, &$extend)
{
if ($class == 'XenForo_Visitor') 
{
$extend[] = 'AvatarGallery_Visitor';
}
}
 
XenForo_Visitor isn't a controller. So it won't work with a load_class_controller event.

You might have more luck with a new code event listener that uses the load_class event. Though I'm not entirely sure if it is possible to extend XenForo_Visitor.

It depends on what you want to do but another option is to use the visitor_setup event. That gives you access to the visitor object.
 
XenForo_Visitor isn't a controller. So it won't work with a load_class_controller event.

You might have more luck with a new code event listener that uses the load_class event. Though I'm not entirely sure if it is possible to extend XenForo_Visitor.

It depends on what you want to do but another option is to use the visitor_setup event. That gives you access to the visitor object.

thanx for the tipp. Now I have this code:

public static function load_class($class, array &$extend)
{

if ($class == 'XenForo_Visitor')

{
$extend[] = 'AvatarGallery_Visitor';
}
}

..and in the class AvatarGallery_Visitor I implemented a modified function of 'canUploadAvatar'.
this is called by : $params['canUploadCustomAvatar'] = $visitor->canUploadAvatar(true);

..but unfortunately the call goes to the parent class and not to the extended class. So I am stuck again :-(
 
What is in the "canUploadAvatar" function? Generally permission checks aren't done like that.
 
thanx for the tipp. Now I have this code:

public static function load_class($class, array &$extend)
{

if ($class == 'XenForo_Visitor')

{
$extend[] = 'AvatarGallery_Visitor';
}
}

..and in the class AvatarGallery_Visitor I implemented a modified function of 'canUploadAvatar'.
this is called by : $params['canUploadCustomAvatar'] = $visitor->canUploadAvatar(true);

..but unfortunately the call goes to the parent class and not to the extended class. So I am stuck again :-(

I have to differenciate two cases: uploading an avatar from a gallery and uploading a user (custom) avatar.
so I modified the function in the extended class

public function canUploadAvatar($withCustomAvatar)
{
$uploadOk = (
$this->_user['user_id']
&& $this->hasPermission('avatar', 'allowed')
&& $this->hasPermission('avatar', 'maxFileSize') != 0
);
if(!$uploadOk){
return false;
}

if($withCustomAvatar && $this->hasPermission('avatar', 'uploadCustomAvatar')){
return true;
}
return false;
}
..but the problem is not the permission, but the fact, that the call goes to the parent class and not to the extended one.

...I now realized that I forgot to add the listener to the ACP list of code event listeners. Things look better now...
 
Last edited:
Top Bottom