2011-08-12 5 views
1

나는 Joomla를 사용하는 것에 익숙하지 않고 v1.5에 대해 쓴 외부 PHP 클래스를 적용하려고합니다. 기본적으로 Joomla 환경을로드하기 위해 Joomla의 모든 기능을 클래스에 사용할 수있는 기능을 사용합니다. 이것은 기본적으로 index.php 파일을 사용하여 수행됩니다.Joomla 1.6 외부 PHP 상호 작용 문제

v1.5에서는 제대로 작동하고 잠시 동안했지만 v1.6에 맞게 조정하려고 시도했지만 넘어졌습니다.

이 같이 말했다
private function loadJoomla() { 
     $path_base = rtrim($this->joomFullPath, '/'); 

     // Set flag that this is a parent file 
     define('_JEXEC', 1); 
     define('DS', DIRECTORY_SEPARATOR); 

     switch ($joomlaVersion) { 
      case 'v1.6': 
       if (file_exists($path_base . '/defines.php')) { 
        include_once $path_base . '/defines.php'; 
       } 
       if (!defined('_JDEFINES')) { 
        define('JPATH_BASE', $path_base); 
        require_once JPATH_BASE.'/includes/defines.php'; 
       } 
       require_once JPATH_BASE.'/includes/framework.php'; 

       // Mark afterLoad in the profiler. 
       JDEBUG ? $_PROFILER->mark('afterLoad') : null; 

       // Instantiate the application. 
       $app = JFactory::getApplication('site'); 

       // Initialise the application. 
       $app->initialise(); 

       // Mark afterIntialise in the profiler. 
       JDEBUG ? $_PROFILER->mark('afterInitialise') : null; 

       // Route the application. 
       $app->route(); 

       // Mark afterRoute in the profiler. 
       JDEBUG ? $_PROFILER->mark('afterRoute') : null; 

       // Dispatch the application. 
       $app->dispatch(); 

       // Mark afterDispatch in the profiler. 
       JDEBUG ? $_PROFILER->mark('afterDispatch') : null; 

       // Render the application. 
       $app->render(); 

       // Mark afterRender in the profiler. 
       JDEBUG ? $_PROFILER->mark('afterRender') : null; 

       // Return the response. 
       return $app; 
      break; 
      case 'v1.5': 
       // PREPARE 
       define('JPATH_BASE', $path_base); 
       require_once (JPATH_BASE .DS.'includes'.DS.'defines.php'); 
       require_once (JPATH_BASE .DS.'includes'.DS.'framework.php'); 
       JDEBUG ? $_PROFILER->mark('afterLoad') : NULL; 

       // CREATE THE APPLICATION 
       $GLOBALS['mainframe'] =& JFactory::getApplication('site'); 

       // INITIALISE THE APPLICATION 
       /* set the language */ 
       $GLOBALS['mainframe']->initialise(); 
       JPluginHelper::importPlugin('system'); 
       /* trigger the onAfterInitialise events */ 
       JDEBUG ? $_PROFILER->mark('afterInitialise') : NULL; 
       $GLOBALS['mainframe']->triggerEvent('onAfterInitialise'); 

       // ROUTE THE APPLICATION 
       $GLOBALS['mainframe']->route(); 
       /* authorization */ 
       $GLOBALS['Itemid'] = JRequest::getInt('Itemid'); 
       $GLOBALS['mainframe']->authorize($GLOBALS['Itemid']); 
       /* trigger the onAfterRoute events */ 
       JDEBUG ? $_PROFILER->mark('afterRoute') : NULL; 
       $GLOBALS['mainframe']->triggerEvent('onAfterRoute'); 

       // DISPATCH THE APPLICATION 
       $GLOBALS['option'] = JRequest::getCmd('option'); 
       $GLOBALS['mainframe']->dispatch($GLOBALS['option']); 
       /* trigger the onAfterDispatch events */ 
       JDEBUG ? $_PROFILER->mark('afterDispatch') : NULL; 
       $GLOBALS['mainframe']->triggerEvent('onAfterDispatch'); 

       // RENDER THE APPLICATION 
       $GLOBALS['mainframe']->render(); 
       /* trigger the onAfterRender events */ 
       JDEBUG ? $_PROFILER->mark('afterRender') : NULL; 
       $GLOBALS['mainframe']->triggerEvent('onAfterRender'); 

       // RETURN THE RESPONSE 
       return JResponse::toString($GLOBALS['mainframe']->getCfg('gzip')); 
      break; 
      default: 
       return NULL; 
      break; 
     } 

의 v1.5에 비트가 잘 작동 및 글로벌 만든 메인 프레임 변수를 그냥 index.php 파일입니다 : 여기

는 기능입니다. v1.6 비트는 '$ app-> dispatch();'에서 넘어집니다.

'die'를 사용하여 흐름을 디버깅하는 것은 /libraries/joomla/application.php의 함수 디스패치로 이동했습니다. 여기서 fall over point는 '$ contents = JComponentHelper :: renderComponent ($ component);'였습니다. 어떤 기능이 필요한지 알았습니다. /libraries/joomla/application/component/helper.php의 renderComponent

나중에 '죽는다'는 것을 알기를 기다리면서, 'ob_start();'를 기다립니다. 특히 v1.5 코드를 체크인 한 이후로 완전히 당혹 스러웠습니다.이 코드는 v1.6과 정확히 동일합니다.

$ app 범위가이 문제의 원인 일 수 있다고 생각하며 도움을 얻을 수 있습니다. 기쁨없이 "$ GLOBALS [ 'app']"을 시도했습니다.

시간과 조언을 주셔서 감사드립니다.

+0

나는 내가 아는 모든 것을 시험해 보았고 다른 곳에서 같은 질문을했지만 매번 침묵의 벽을 만났다. 나는이 문제의 원인을 어떻게 표현했는지 궁금합니다. 가능한 경우 도와주세요. 감사 – Dayo

답변

2

다음과 같이이 문제를 해결할 수있었습니다.

두 가지 문제가 발생했습니다.

첫째, v1.6 섹션에 "$ option"매개 변수가 올바르게 초기화되지 않았습니다. this query I made의 사용자 비트로 인해 나는 그것을 풀 수 있었다. 문제가 해결되지 않았다 그러나

// Dispatch the application. 
$option = JRequest::getCmd('option'); 
$app->dispatch($option); 

, 그리고 코드는 여전히 '위한 ob_start'지점에서 충돌하고 다음과 같이 코드를 변경하여.

두 번째로 나는 충돌의 실제 이유를 알 수 없었지만 해결 방법을 찾으러갔습니다. 문제의 ob_start 비트는 /libraries/joomla/application/component/helper.php에 있기 때문에 변수에 구성 요소 출력을 수집하기위한 용도로만 사용할 수 있습니다. '$ app-> dispatch ($ 옵션) '이 내 파일에 실행되고 문제가 수정되었습니다. 다음과 같이

첫째, 메인 섹션을 수정이와

private function joomdispatch($option) { 
    /************************ 
    * This is pulled from function 'render' 
    * in /libraries/joomla/application.php 
    ************************/ 
    $document = JFactory::getDocument(); 
    $document->setTitle(JApplication::getCfg('sitename'). ' - ' .JText::_('JADMINISTRATION')); 
    $document->setDescription(JApplication::getCfg('MetaDesc')); 

    /************************ 
    * This is pulled from function 'renderComponent' 
    * in /libraries/joomla/application/component/helper.php 
    * Function 'renderComponent' is called by the 
    * '$contents = JComponentHelper::renderComponent($component);' line 
    * We exclude that line and jump to the function code 
    ************************/ 

    // Initialise variables. 
    $app = JFactory::getApplication(); 

    // Load template language files. 
    $template = $app->getTemplate(true)->template; 
    $lang = JFactory::getLanguage(); 
    $lang->load('tpl_'.$template, JPATH_BASE, null, false, false) 
     || $lang->load('tpl_'.$template, JPATH_THEMES."/$template", null, false, false) 
     || $lang->load('tpl_'.$template, JPATH_BASE, $lang->getDefault(), false, false) 
     || $lang->load('tpl_'.$template, JPATH_THEMES."/$template", $lang->getDefault(), false, false); 

    $scope = $app->scope; //record the scope 
    $app->scope = $option; //set scope to component name 

    // Build the component path. 
    $option = preg_replace('/[^A-Z0-9_\.-]/i', '', $option); 
    $file = substr($option, 4); 

    // Define component path. 
    define('JPATH_COMPONENT',    JPATH_BASE.DS.'components'.DS.$option); 
    define('JPATH_COMPONENT_SITE',   JPATH_SITE.DS.'components'.DS.$option); 
    define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR.DS.'components'.DS.$option); 

    // get component path 
    if ($app->isAdmin() && file_exists(JPATH_COMPONENT.DS.'admin.'.$file.'.php')) { 
     $path = JPATH_COMPONENT.DS.'admin.'.$file.'.php'; 
    } else { 
     $path = JPATH_COMPONENT.DS.$file.'.php'; 
    } 

    $task = JRequest::getString('task'); 

    // Load common and local language files. 
    $lang->load($option, JPATH_BASE, null, false, false) 
     || $lang->load($option, JPATH_COMPONENT, null, false, false) 
     || $lang->load($option, JPATH_BASE, $lang->getDefault(), false, false) 
     || $lang->load($option, JPATH_COMPONENT, $lang->getDefault(), false, false); 

    // Handle template preview outlining. 
    $contents = null; 

    // Get component html 
    /************************ 
    * This has been edited from the native 'ob_start'. 
    * Could use curl as well 
     ***********************/ 
    $contents = file_get_contents($this->joomUrl . '/index.php?' . $this->joomQS); 

    // Build the component toolbar 
    jimport('joomla.application.helper'); 

    if (($path = JApplicationHelper::getPath('toolbar')) && $app->isAdmin()) { 
     // Get the task again, in case it has changed 
     $task = JRequest::getString('task'); 

     // Make the toolbar 
     include_once $path; 
    } 

    $app->scope = $scope; //revert the scope 

    /************************ 
    * Back to function 'renderComponent' code 
    * to complete process 
    ************************/ 
    $document->setBuffer($contents, 'component'); 

    // Trigger the onAfterDispatch event. 
    JPluginHelper::importPlugin('system'); 
    JApplication::triggerEvent('onAfterDispatch'); 
} 

이 모든 것이 잘 작동 다음과 같이

// Dispatch the application. 
$option = JRequest::getCmd('option'); 
/** The process crashes here for some reason 
* (See https://stackoverflow.com/questions/7039162/). 
* So we comment out the Joomla! function, pull the code in here and 
* push the component content into the Joomla document buffer ourselves. 
**/ 
//$app->dispatch($option); 
$this->joomdispatch($option); 

내가 다음 'joomdispatch'기능을 썼다. didn''t는 (이상한) 오류의 바닥에 도착한다. 그러나 그럭저럭 돌아 다니기 위해 관리 할 수 ​​있었다.