Exemple #1
0
 /**
  * Fetches a language package from the remote server
  *
  * @param string $languageCode
  *
  * @return array
  */
 public function fetchPackage($languageCode)
 {
     // Check if we have a cache file, generate it if not
     if (!is_readable($this->cacheFile)) {
         $this->fetchLanguages();
     }
     $cacheData = json_decode(file_get_contents($this->cacheFile), true);
     // Make sure the language actually exists
     if (!isset($cacheData['languages'][$languageCode])) {
         return array('error' => true, 'message' => 'mautic.core.language.helper.invalid.language');
     }
     // GET the update data
     try {
         $data = $this->connector->get('https://updates.mautic.org/index.php?option=com_mauticdownload&task=downloadLanguagePackage&langCode=' . $languageCode);
     } catch (\Exception $exception) {
         $logger = $this->factory->getLogger();
         $logger->addError('An error occurred while attempting to fetch the package: ' . $exception->getMessage());
         return array('error' => true, 'message' => 'mautic.core.language.helper.error.fetching.package');
     }
     if ($data->code != 200) {
         return array('error' => true, 'message' => 'mautic.core.language.helper.error.fetching.package');
     }
     // Set the filesystem target
     $target = $this->factory->getSystemPath('cache') . '/' . $languageCode . '.zip';
     // Write the response to the filesystem
     file_put_contents($target, $data->body);
     // Return an array for the sake of consistency
     return array('error' => false);
 }
Exemple #2
0
 /**
  * Shorten a URL.
  *
  * @param $url
  *
  * @return mixed
  */
 public function buildShortUrl($url)
 {
     if (!$this->shortnerServiceUrl) {
         return $url;
     }
     try {
         $response = $this->http->get($this->shortnerServiceUrl . urlencode($url));
         if ($response->code === 200) {
             return rtrim($response->body);
         } elseif ($this->logger) {
             $this->logger->addWarning("Url shortner failed with code {$response->code}: {$response->body}");
         }
     } catch (\Exception $exception) {
         if ($this->logger) {
             $this->logger->addError($exception->getMessage(), ['exception' => $exception]);
         }
     }
     return $url;
 }
Exemple #3
0
 /**
  * Fetches a download package from the remote server
  *
  * @param string $package
  *
  * @return array
  */
 public function fetchPackage($package)
 {
     // GET the update data
     try {
         $data = $this->connector->get($package);
     } catch (\Exception $exception) {
         $logger = $this->factory->getLogger();
         $logger->addError('An error occurred while attempting to fetch the package: ' . $exception->getMessage());
         return array('error' => true, 'message' => 'mautic.core.updater.error.fetching.package');
     }
     if ($data->code != 200) {
         return array('error' => true, 'message' => 'mautic.core.updater.error.fetching.package');
     }
     // Set the filesystem target
     $target = $this->factory->getSystemPath('cache') . '/' . basename($package);
     // Write the response to the filesystem
     file_put_contents($target, $data->body);
     // Return an array for the sake of consistency
     return array('error' => false);
 }
 /**
  * @param  Request        $request
  * @return JoomlaResponse
  */
 protected function get(Request $request)
 {
     return $this->http->get((string) $request->getUrl(), $request->getHeaders());
 }