Solved Fix PHP download error

Yun Hee Ji

Registered
Registered
Joined
Jul 22, 2019
Messages
11
Reaction score
13
Hiya, I've wanted to help with this add-on which is not working at the latest version It can cause A server error occurred. Please try again later.,

SyTry CRUEL-MODZ

Server error logs:
Code:
[LIST]
[*]ErrorException: [E_WARNING] Trying to access array offset on value of type null
[*]src/addons/XenSoluce/LikeReplyDownloadRM/XFRM/Pub/Controller/ResourceItem.php:391
[*]Generated by: Tifa
[*]Mar 30, 2024 at 8:38 PM
[/LIST]
[HEADING=2]Stack trace[/HEADING]
#0 src/addons/XenSoluce/LikeReplyDownloadRM/XFRM/Pub/Controller/ResourceItem.php(391): XF::handlePhpError(2, '[E_WARNING] Try...', '/var/www/vhosts...', 391)
#1 src/addons/XenSoluce/LikeReplyDownloadRM/XFRM/Pub/Controller/ResourceItem.php(80): XenSoluce\LikeReplyDownloadRM\XFRM\Pub\Controller\ResourceItem->canReactionView(NULL, Object(SV\MultiPrefix\XFRM\Entity\ResourceItem))
#2 src/XF/Mvc/Dispatcher.php(352): XenSoluce\LikeReplyDownloadRM\XFRM\Pub\Controller\ResourceItem->actionDownload(Object(XF\Mvc\ParameterBag))
#3 src/XF/Mvc/Dispatcher.php(259): XF\Mvc\Dispatcher->dispatchClass('XFRM:ResourceIt...', 'Download', Object(XF\Mvc\RouteMatch), Object(XenConcept\DownloadTracker\XFRM\Pub\Controller\ResourceItem), NULL)
#4 src/XF/Mvc/Dispatcher.php(115): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XenConcept\DownloadTracker\XFRM\Pub\Controller\ResourceItem), NULL)
#5 src/XF/Mvc/Dispatcher.php(57): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#6 src/XF/App.php(2487): XF\Mvc\Dispatcher->run()
#7 src/XF.php(524): XF\App->run()
#8 index.php(20): XF::runApp('XF\\Pub\\App')
#9 {main}
[HEADING=2]Request state[/HEADING]
array(4) {
  ["url"] => string(45) "/resources/long-sleeves-for-cloud.19/download"
  ["referrer"] => string(61) "https://animetest.com/resources/tifa-mods-cutie.1/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}

I found out and fixed it,
1 Before:
Code:
    protected function setupResourceEdit(\XFRM\Entity\ResourceItem $resource)
    {
        $editor =  parent::setupResourceEdit($resource);
        if(!\xf::visitor()->hasPermission('resource', 'canEditParam')){
            $lrdrm = ['type' => 'permission', 'enable' => true];
        }
        else{
            $input = $this->filter(['type' => 'str', 'enable' => 'int']);
            if($input['enable']){
                if($input['type'] == 'custom'){
                    $lrdrm = $this->filter([
                        'enable' => 'int',
                        'type' => 'str',
                        'reactreply' => 'int',
                        'reactionId' => 'array-int',
                    ]);
                }
                else{
                    $lrdrm = ['type' => $input['type'], 'enable' => $input['enable']];   
                }
            }
            else{
                $lrdrm = ['enable' => $input['enable']];
            }
        }
        $editor->setLrdrm($lrdrm);
        return $editor;
    }

After:
Code:
protected function setupResourceEdit(\XFRM\Entity\ResourceItem $resource): \XF\Entity\Editor {
    $editor = parent::setupResourceEdit($resource);
   
    if(!\XF::visitor()->hasPermission('resource', 'canEditParam')){
        $lrdrm = ['type' => 'permission', 'enable' => true];
    } else {
        $input = $this->filter(['type' => 'str', 'enable' => 'int']);
        if($input['enable']){
            if($input['type'] == 'custom'){
                $lrdrm = $this->filter([
                    'enable' => 'int',
                    'type' => 'str',
                    'reactreply' => 'int',
                    'reactionId' => 'array-int',
                ]);
            } else {
                $lrdrm = ['type' => $input['type'], 'enable' => $input['enable']];
            }
        } else {
            $lrdrm = ['enable' => $input['enable'] ?? 0];
        }
    }
   
    $editor->setLrdrm($lrdrm);
    return $editor;
}


2 Before:
Code:
    public function canReactionView($likerfinder, \XFRM\Entity\ResourceItem $resource)
    {
        if($resource["xs_lrdrm"]['type'] == 'custom'){
            if(!in_array($likerfinder["Reaction"]["reaction_id"], $resource["xs_lrdrm"]['reactionId'])){
                $likerfinder = 0;
            }
        }
        else{
            $option = \xf::options()->xs_lrdrm_react_type;
            if($option['type'] == '2'){
                if(!$likerfinder['Reaction']['reaction_score'] ||
                $likerfinder['Reaction']['reaction_score'] <= -1){
                    $likerfinder = 0;
                }
            }
            elseif($option['type'] == '3'){
                if(!in_array($likerfinder["Reaction"]["reaction_id"], $option['react'])){
                    $likerfinder = 0;
                }
            }
        }
        return $likerfinder;
    }
}

After:
Code:
public function canReactionView($likerfinder, \XFRM\Entity\ResourceItem $resource)
{
    if ($likerfinder !== null && $resource["xs_lrdrm"]['type'] == 'custom') {
        if (!empty($likerfinder["Reaction"]["reaction_id"]) && !in_array($likerfinder["Reaction"]["reaction_id"], $resource["xs_lrdrm"]['reactionId'])) {
            $likerfinder = 0;
        }
    } else {
        $option = \xf::options()->xs_lrdrm_react_type;
        if ($option['type'] == '2') {
            if (!empty($likerfinder['Reaction']['reaction_score']) && $likerfinder['Reaction']['reaction_score'] <= -1) {
                $likerfinder = 0;
            }
        } elseif ($option['type'] == '3') {
            if (!empty($likerfinder["Reaction"]["reaction_id"]) && !in_array($likerfinder["Reaction"]["reaction_id"], $option['react'])) {
                $likerfinder = 0;
            }
        }
    }
    return $likerfinder;
   }
}
 
Hello,

Which version of Xenforo? thanks for your help!

But obviously you didn't have a license for this addon? If it's for testing purposes and not on a production site, there's no problem, but if it's on a production site, please license this addon ;)

Regards, CRUEL-MODZ
 
Hello,

Which version of Xenforo? thanks for your help!

But obviously you didn't have a license for this addon? If it's for testing purposes and not on a production site, there's no problem, but if it's on a production site, please license this addon ;)

Regards, CRUEL-MODZ
No worries, it's a local host.

The edit resource cause stopped working and I fixed this,
Code:
protected function setupResourceEdit(\XFRM\Entity\ResourceItem $resource): \XF\Entity\Editor {
    // Call the parent method
    $editor = parent::setupResourceEdit($resource);

    // Ensure $editor is of the expected type or handle it appropriately
    if (!($editor instanceof \XF\Entity\Editor)) {
        // Handle unexpected return type here, or log an error
        // For example, you might return a default Editor instance
        $editor = \XF::app()->service('XF:Editor', 'message', []);
    }

    // Fixed Edit Resource issue
    if (!\XF::visitor()->hasPermission('resource', 'canEditParam')) {
        $lrdrm = ['type' => 'permission', 'enable' => true];
    } else {
        $input = $this->filter(['type' => 'str', 'enable' => 'int']);
        if ($input['enable']) {
            if ($input['type'] == 'custom') {
                $lrdrm = $this->filter([
                    'enable' => 'int',
                    'type' => 'str',
                    'reactreply' => 'int',
                    'reactionId' => 'array-int',
                ]);
            } else {
                $lrdrm = ['type' => $input['type'], 'enable' => $input['enable']];
            }
        } else {
            $lrdrm = ['enable' => $input['enable'] ?? 0];
        }
    }

    $editor->setLrdrm($lrdrm);

    return $editor;
}
 
Hello,

Which version of Xenforo? thanks for your help!

But obviously you didn't have a license for this addon? If it's for testing purposes and not on a production site, there's no problem, but if it's on a production site, please license this addon ;)

Regards, CRUEL-MODZ
Hey, I’m sorry I didn’t see that you mentioned as XenForo version. It’s v2.2.15
 
Top Bottom