/** * * @param type $sPath * @return type */ public function getFileContents($sPath, $aPost = array(), $sOrigPath = '') { if (strpos($sPath, 'http') === 0 || !empty($aPost)) { if (!$this->oHttpAdapter->available()) { throw new Exception(JchPlatformUtility::translate('No Http Adapter available')); } try { $response = $this->oHttpAdapter->request($sPath, $aPost); if ($response === FALSE) { throw new RuntimeException(sprintf(JchPlatformUtility::translate('Failed getting file contents from %s'), $sPath)); } } catch (RuntimeException $ex) { JchOptimizelogger::log($sPath . ': ' . $ex->getMessage(), JchPlatformPlugin::getPluginParams()); $response['code'] = 404; } catch (BadFunctionCallException $ex) { throw new Exception($ex->getMessage()); } if ($response['code'] >= 400) { $sPath = $sOrigPath == '' ? $sPath : $sOrigPath; $sContents = $this->notFound($sPath); } else { $sContents = $response['body']; } } else { if (file_exists($sPath)) { $sContents = @file_get_contents($sPath); } elseif ($this->oHttpAdapter->available()) { $sUriPath = JchPlatformPaths::path2Url($sPath); $sContents = $this->getFileContents($sUriPath, array(), $sPath); } else { $sContents = $this->notFound($sPath); } } return $sContents; }
/** * * @param type $type * @param type $parent */ public function postflight($type, $parent) { require_once JPATH_ROOT . '/plugins/system/jch_optimize/jchoptimize/loader.php'; require_once JPATH_ROOT . '/plugins/system/jch_optimize/fields/autoorder.php'; if ($type == 'install') { JFormFieldAutoorder::fixFilePermissions(true); } if ($type == 'update') { JFormFieldAutoorder::cleanCache(true); $params = JchPlatformPlugin::getPluginParams(); if (($exludeAllExtensions = $params->get('excludeAllExtensions', '')) !== '') { $params->set('includeAllExtensions', !$exludeAllExtensions); $params->set('excludeAllExtensions', ''); JchPlatformPlugin::saveSettings($params); } } JFormFieldAutoorder::orderPlugins(true); }
/** * * @param type $sPath * @return type */ public function getFileContents($sPath, $aPost = null, $aHeader = null, $sOrigPath = '') { $oHttpAdapter = $this->getHttpAdapter(); if (strpos($sPath, 'http') === 0) { if (!$oHttpAdapter->available()) { throw new Exception('No Http Adapter available'); } $this->response_code = 0; try { $sUserAgent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $response = $oHttpAdapter->request($sPath, $aPost, $aHeader, $sUserAgent); $this->response_code = $response['code']; if (!isset($response) || $response === FALSE) { throw new RuntimeException(sprintf('Failed getting file contents from %s', $sPath)); } } catch (RuntimeException $ex) { JchOptimizelogger::log($sPath . ': ' . $ex->getMessage(), JchPlatformPlugin::getPluginParams()); } catch (Exception $ex) { throw new Exception($sPath . ': ' . $ex->getMessage()); } if ($this->response_code != 200 && !$this->allow_400) { $sPath = $sOrigPath == '' ? $sPath : $sOrigPath; $sContents = $this->notFound($sPath); } else { $sContents = $response['body']; } } else { if (file_exists($sPath)) { $sContents = @file_get_contents($sPath); } elseif ($oHttpAdapter->available()) { $sUriPath = JchPlatformPaths::path2Url($sPath); $sContents = $this->getFileContents($sUriPath, null, null, $sPath); } else { $sContents = $this->notFound($sPath); } } return $sContents; }