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

Annoying $GLOBALS['fc'] Issue

Discussion in 'XenForo Development Discussions' started by ibnesayeed, Dec 19, 2011.

  1. ibnesayeed

    ibnesayeed Well-Known Member

    We are using Admin Language add-on by Nabeel. It helps keeping ACP language in English no matter what language is selected for public interface.

    Our Server Error Log is filled up by following error.

    Code:
    ErrorException: Undefined index:  fc - library/Nabeel/AdminLanguage/Visitor/Setup.php:9
    Here is the stack trace.

    Code:
    #0 library/Nabeel/AdminLanguage/Visitor/Setup.php(9): XenForo_Application::handlePhpError(Object(XenForo_Visitor))
    #1 [internal function]: Nabeel_AdminLanguage_Visitor_Setup::listen(Array, Array)
    #2 library/XenForo/CodeEvent.php(54): call_user_func_array('visitor_setup', Array)
    #3 library/XenForo/Visitor.php(426): XenForo_CodeEvent::fire(0)
    #4 library/XenForo/Visitor.php(81): XenForo_Visitor::setup()
    #5 library/XenForo/Visitor.php(104): XenForo_Visitor::getInstance()
    #6 library/XenForo/NodeHandler/Forum.php(82): XenForo_Visitor::getUserId(Array)
    #7 library/XenForo/Model/Node.php(565): XenForo_NodeHandler_Forum->getExtraDataForNodes(Array, Array)
    #8 library/XenForo/Model/Node.php(803): XenForo_Model_Node->mergeExtraNodeDataIntoNodeList()
    #9 library/XenForo/Model/Counters.php(16): XenForo_Model_Node->getNodeTotalItemCounts()
    #10 library/XenForo/Model/Counters.php(37): XenForo_Model_Counters->getBoardTotalsCounter()
    #11 library/XenForo/CronEntry/Counters.php(15): XenForo_Model_Counters->rebuildBoardTotalsCounter(Array)
    #12 [internal function]: XenForo_CronEntry_Counters::rebuildBoardTotals(Array, Array)
    #13 library/XenForo/Model/Cron.php(356): call_user_func(Array)
    #14 library/XenForo/Cron.php(29): XenForo_Model_Cron->runEntry()
    #15 library/XenForo/Cron.php(64): XenForo_Cron->run()
    #16 cron.php(12): XenForo_Cron::runAndOutput()
    #17 {main}
    And here is the add-on code.

    PHP:
    <?php
    class Nabeel_AdminLanguage_Visitor_Setup
    {
        public static function 
    listen(XenForo_Visitor &$visitor)
        {
            
    // get the Xenforo_FrontController instance
            
    $frontController$GLOBALS['fc'];
            
    // get the dependencies object
            
    $dependencies=  $frontController->getDependencies();
     
            
    // check if it is the admin back-end
            //if(is_a($dependencies, "XenForo_Dependencies_Admin"))
            
    if($dependencies instanceof XenForo_Dependencies_Admin)
            {
                    
    $options XenForo_Application::get('options');
                    
    $settingEnabled$options->admin_language_setting_enabled;
                    if (
    $settingEnabled)
                    {
                        
    $languageId=$options->admin_language_preset;
                                    
    $visitor->setVisitorLanguage($languageId);
                    }
            }
     
        }
    }
    ?>
    Any thoughts how to fix this? :)
     
    simunaqv likes this.
  2. Rigel Kentaurus

    Rigel Kentaurus Well-Known Member

    You could do

    PHP:
            // get the Xenforo_FrontController instance
            
    $frontController= isset($GLOBALS['fc']) ? $GLOBALS['fc'] : null;
            
    // get the dependencies object
            
    $dependencies$frontController $frontController->getDependencies() : null;
     
  3. ibnesayeed

    ibnesayeed Well-Known Member

    Thanks a lot. I have added this patch and everything seems good. :)
     
    ARSamo and simunaqv like this.

Share This Page