警告:非法字符串偏移

时间:2015-07-16 17:30:17

标签: php

我正在运行ipb并且我正在使用名为ibeconomy的插件,在用户购买并从商店获奖并使用它后,他们会收到此错误。警告:第196行非法字符串偏移'错误'/ibEconomy/sources/shop_items/award_item.php。

if(!$ returnMe ['error'])

这是代码,我不确定究竟发生了什么。     

/**
 * (e34) ibEconomy
 * Shop Item: Award Item
 */

if ( ! defined( 'IN_IPB' ) )
{
    print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
    exit();
}

class class_shop_item implements ibEconomy_shop_item
{
    protected $registry;
    protected $DB;
    protected $settings;
    protected $request;
    protected $lang;
    protected $member;
    protected $cache;   

    /**
     * Class entry point
     */
    public function __construct( ipsRegistry $registry )
    {
        $this->registry     =  ipsRegistry::instance();
        $this->DB           =  $this->registry->DB();
        $this->settings     =& $this->registry->fetchSettings();
        $this->request      =& $this->registry->fetchRequest();
        $this->lang         =  $this->registry->getClass('class_localization');
        $this->member       =  $this->registry->member();
        $this->memberData   =& $this->registry->member()->fetchMemberData();
        $this->cache        =  $this->registry->cache();
        $this->caches       =& $this->registry->cache()->fetchCaches(); 
    }

    //*************************//
    //($%^   ADMIN STUFF   ^%$)//
    //*************************//   

    /**
     * Send the "Stock" Title
     */
    public function title()
    {
        return $this->lang->words['award_item'];
    }

    /**
     * Send the "Stock" Description
     */
    public function description()
    {
        return $this->lang->words['award_description'];
    }

    /**
     * Need to pick self or others applicable?
     */
    public function otherOrSelf()
    {
        return TRUE;
    }   

    /**
     * Send the Extra Settings
     */
    public function extra_settings()
    {
        $itemSettings = array( 0 => array( 'form_type'  => 'formDropdown',
                                           'field'      => 'si_extra_settings_1',
                                           'words'      => $this->lang->words['which_award'],
                                           'type'       => 'awards'
                                         ),
                               1  => array( 'form_type' => 'formMultiDropdown',
                                            'field'     => 'si_protected_g',
                                            'words'     => $this->lang->words['protected_groups'],
                                            'desc'      => $this->lang->words['cannot_be_done_to_groups'],
                                            'type'      => 'groups'
                                         ),
                               2  => array( 'form_type' => 'forminput',
                                            'field'     => 'si_extra_settings_2',
                                            'words'     => $this->lang->words['reason_for_award'],
                                         )
                             );

        return $itemSettings;
    }

    //*************************//
    //($%^   PUBLIC STUFF   ^%$)//
    //*************************//   

    /**
     * Using Item HTML
     */
    public function usingItem($theItem)
    {
        $itemHtml = array();

        #need member name input?
        if ( $theItem['si_other_users'] )
        {
            $itemHtml[] = array('text' => $this->lang->words['input_member_name'], 'inputs' => "<input type='text' size='30' name='mem_name' id='mem_name1' />");

            if ( $theItem['si_allow_user_pm'] )
            {
                $itemHtml[] = array('text' => $this->lang->words['input_message']."<br /><span class='desc'>{$this->lang->words['optional_message']}</span>", 'inputs' => "<textarea size='50' cols='40' rows='5' wrap='soft' name='message' id='message' class='multitext'></textarea>");
            }               
        }

        return $itemHtml;
    }

    /**
     * Use Item
     */
    public function useItem($theItem,$myPortItem)
    {
        #init
        $returnMe   = '';
        $memName    = $this->request['mem_name'];
        $usrMessage = trim(IPSText::getTextClass( 'bbcode' )->stripBadWords( $this->request['message'] ));
        $msg2send   = '';       

        #no member?
        if ( $theItem['si_other_users'] )
        {
            #input?
            if ( !$memName )
            {
                $returnMe['error'] = $this->lang->words['no_member_entered'];
            }
            else
            {
                #load item recipient
                $daMember = IPSMember::load( $memName, 'all', 'displayname' );              
            }

            #no one found?
            if ( !$returnMe['error'] && !$daMember['member_id'] )
            {   
                $returnMe['error'] = $this->lang->words['no_member_found_by_id'];           
            }

            #your own self, when not allowed?
            if ( !$returnMe['error'] && $daMember['member_id'] == $this->memberData['member_id'] )
            {
                $returnMe['error'] = $this->lang->words['item_cannot_be_done_on_self'];
            }           

            #member in protected group?
            if ( !$returnMe['error'] && in_array( $daMember['member_group_id'], explode(',', $theItem['si_protected_g']) ) )
            {
                $returnMe['error'] = $this->lang->words['member_in_protected_group'];
            }

            #send message about item use?
            if ( $theItem['si_allow_user_pm'] && $usrMessage != "" )
            {
                $msg2send = $usrMessage;
                $sender = $this->memberData['member_id'];
            }
            else if ( trim($theItem['si_default_pm']) != "" )
            {
                $msg2send = trim($theItem['si_default_pm']);
            }
        }
        else        
        {
            $daMember = $this->memberData;
        }       

        #reason for "award" and which award?
        $reason         = $theItem['si_extra_settings_2'];
        $catAndAwardID  = explode('_', $theItem['si_extra_settings_1']);

        if ($this->settings['awds_system_status'] === '0' || $this->settings['awds_system_status'] === '1')
        {
            $award      = $this->DB->buildAndFetch( array(  'select'    => '*',
                                                            'from'   => 'inv_awards',
                                                            'where'  => 'id = ' . $catAndAwardID[1],
                                            )       );

            $awardName      = $award['name'];
        }
        else
        {
            $awardName      = $this->caches['awards_cat_cache'][ $catAndAwardID[0] ]['awards'][ $catAndAwardID[1] ]['awards_name'];
        }

        #no errors, use it!
        if ( ! $returnMe['error'] )
        {
            #use it
            $this->doUseItem($daMember['member_id'], $reason, $theItem['si_extra_settings_1']);

            #send PM
            if ( $msg2send != '' )
            {           
                $title = sprintf( $this->lang->words['shop_item_used_on_you'], $theItem['si_title'] );

                $this->registry->ecoclass->sendPM($daMember['member_id'] , '', 0, '', 'generic', $msg2send, $title, $sender, $awardName );          
            }

            #finish up
            $this->registry->ecoclass->finishUpItemUse($theItem,$myPortItem,$daMember['members_display_name'] != $this->memberData['members_display_name'] ? $daMember['members_display_name'] : '');

            #add to redirect text
            $returnMe['redirect_text'] = $this->lang->words['item_has_been_added'] ;
        }

        return $returnMe;
    }

    /**
     * Use Item EXECUTION
     */
    public function doUseItem($member_id, $awards_reason, $awardIdAndCat)
    {   
        #add "award" to mid's profile.  
        $awarder_id         = ($member_id != $this->memberData['member_id']) ? $this->memberData['member_id'] : $this->settings['eco_shopitems_pm_sender'];

        $app_cache  = $this->cache->getCache('app_cache');
        $pinAwards  = $app_cache['awards'];
        $jAwards    = $app_cache['jawards'];

        #Get the reason ready for parsing
        IPSText::getTextClass('bbcode')->parse_html     = 0;
        IPSText::getTextClass('bbcode')->parse_nl2br    = 1;
        IPSText::getTextClass('bbcode')->parse_smilies  = 1;
        IPSText::getTextClass('bbcode')->parse_bbcode   = 1;
        IPSText::getTextClass('bbcode')->parsing_section= 'awards_reason';

        $awards_reason = IPSText::getTextClass('bbcode')->preDbParse( $awards_reason );
        $lang = $this->lang->words['awards_system_give'];
        $awarded_date = date('Y-m-d H:i:s');

        #Get the award id of the award being given
        #explode $awards_action around '_'
        $action_array   = explode('_',$awardIdAndCat);
        $cat_id         = $action_array[0];
        $award_id       = $action_array[1];

        //Which Awards System are we using?  INV perhaps?
        if ($jAwards['app_enabled'])
        {
            if(!$this->registry->isClassLoaded('admin_jawards_functions')) {
                require_once( IPSLib::getAppDir( 'jawards' ) . "/sources/classes/jawards/class_jawards.php" );
                require_once( IPSLib::getAppDir( 'jawards' ) . "/sources/classes/jawards/admin_jawards_functions.php" );
                $classToLoad = IPSLib::loadLibrary( IPSLib::getAppDir( 'jawards' ) . "/sources/classes/jawards/admin_jawards_functions.php", "admin_jawards_functions", 'jawards' );
                $this->registry->setClass( 'admin_jawards_functions', new $classToLoad( $this->registry ) );
            }       
            $this->registry->getClass('admin_jawards_functions')->giveAward($award_id, $member_id, $awards_reason);                         
        }
        //Nope, we are using PIN
        else
        {
            if(!$this->registry->isClassLoaded('classAwards')) {
                require_once( IPSLib::getAppDir( 'awards' ) . "/sources/classes/classAwards.php" );
                $classToLoad = IPSLib::loadLibrary( IPSLib::getAppDir( 'awards' ) . "/sources/classes/classAwards.php", "class_awards", 'awards' );
                $this->registry->setClass( 'classAwards', new $classToLoad( $this->registry ) );
            }
            $this->registry->getClass( 'classAwards' )->addAward($award_id, $member_id, $awarder_id, $awards_reason);       
        }       
    }
}

2 个答案:

答案 0 :(得分:0)

您将$returnMe初始化为空字符串,但您尝试将其用作关联数组。您应该将其初始化为空数组。所以改变这一行:

$returnMe   = '';

为:

$returnMe = array();

答案 1 :(得分:0)

$returnMe目前是一个字符串。它不是一个数组。你应该这样做:

$returnMe = []; // or array() for php < 5.4 

...

if (!is_null($returnMe['error'])){

    // Here you can evaluate $returnMe['error']

}