/** * Get the location based on freegeoip * * @return bool|string * * @since 5.1.0 */ protected static function getGeolocation() { $ip = self::getUserIp(); $url = 'http://freegeoip.net/json/' . $ip; $options = new JRegistry(); $transport = new JHttpTransportCurl($options); // Create a 'curl' transport. $http = new JHttp($options, $transport); $http->setOption('timeout', 5); try { $get = $http->get($url); } catch (Exception $e) { return false; } if ($get->code === 200) { $body = json_decode($get->body); $text = 'Unknown'; // Small to large areas if (!empty($body->city)) { $text = $body->city; } elseif (!empty($body->zip_code)) { $text = $body->zip_code; } elseif (!empty($body->region_name)) { $text = $body->region_name; } elseif (!empty($body->country_name)) { $text = $body->country_name; } return array('lat' => $body->latitude, 'lng' => $body->longitude, 'text' => $text); } return false; }
/** * Initialize the video */ private function _init() { StreamFactory::load('libraries.slideshare'); jimport('joomla.http.http'); $feedURL = 'http://www.slideshare.net/api/oembed/2?url=' . $this->source . '&format=json'; $options = new JRegistry(); $transport = new JHttpTransportCurl($options); $http = new JHttp($options, $transport); $response = $http->get($feedURL); $this->response = $response->body; return true; }
public function init($url) { jimport('joomla.http.http'); $this->url = $url; $this->videoId = $this->getId(); $feedURL = 'http://gdata.youtube.com/feeds/api/videos/' . $this->videoId; $options = new JRegistry(); $transport = new JHttpTransportCurl($options); $http = new JHttp($options, $transport); $response = $http->get($feedURL); $this->xmlContent = $response->body; return true; }
/** * Fetch google map data refere to * http://code.google.com/apis/maps/documentation/geocoding/#Geocoding */ public static function getAddressData($address) { $url = JMap::GEOCODE_URL . 'address=' . urlencode($address) . '&sensor=false'; $options = new JRegistry(); $transport = new JHttpTransportCurl($options); $http = new JHttp($options, $transport); $response = $http->get($url); $content = $response->body; $status = null; if (!empty($content)) { $status = json_decode($content); } return $status; }
public function init($url) { jimport('joomla.http.http'); $this->url = $url; $this->videoId = $this->getId(); $feedURL = 'http://vimeo.com/api/v2/video/' . $this->videoId . '.json'; $options = new JRegistry(); $transport = new JHttpTransportCurl($options); $http = new JHttp($options, $transport); $response = $http->get($feedURL); $this->responseObj = json_decode($response->body); $this->responseObj = $this->responseObj[0]; // only take the first response return true; }
/** * Get a single row * * @return step object */ public function requestRest($task = 'total', $table = false, $chunk = false) { // JHttp instance jimport('joomla.http.http'); $http = new JHttp(); $data = $this->getRestData(); // Getting the total $data['task'] = $task; $data['table'] = $table !== false ? $table : ''; $data['chunk'] = $chunk !== false ? $chunk : ''; $data['keepid'] = $this->params->keep_ids ? $this->params->keep_ids : 0; $request = $http->get($this->params->rest_hostname . '/index.php', $data); $code = $request->code; if ($code == 500) { throw new Exception('COM_JUPGRADEPRO_ERROR_REST_REQUEST'); } else { return $code == 200 || $code == 301 ? $request->body : $code; } }
/** * Method to send the request which does not require authentication. * * @param string $path The path of the request to make * @param string $method The request method. * @param array $headers The headers passed in the request. * @param mixed $data Either an associative array or a string to be sent with the post request. * * @return SimpleXMLElement The XML response * * @since 13.1 * @throws DomainException */ public function sendRequest($path, $method = 'GET', $headers = array(), $data = '') { // Send the request. switch ($method) { case 'GET': $response = $this->client->get($path, $headers); break; case 'POST': $response = $this->client->post($path, $data, $headers); break; } // Validate the response code. if ($response->code != 200) { $error = htmlspecialchars($response->body); throw new DomainException($error, $response->code); } $xml_string = simplexml_load_string($response->body); return $xml_string; }
/** * Check repository server * * @return bool|False */ public function check() { if (empty($this->location)) { return false; } $key = $this->_tbl_key; if (!$this->{$key}) { $site_uri = JUri::getInstance()->base(); $http = new JHttp(); $callback_function = 'mp'; $repository = JUri::getInstance($this->location); $repository->setVar('callback', $callback_function); $response = $http->get($repository, array('referer' => $site_uri)); if (200 != $response->code) { return $this->error($this->location, JText::sprintf('COM_MARKETPLACE_REPOSITORY_OPEN_URL', $url)); } if (strpos($response->body, $callback_function . '(') === false) { return $this->error($this->location, JText::_('COM_MARKETPLACE_REPOSITORY_RESPONSE_DONT_SUPPORT_JSONP')); } $response->body = substr($response->body, 3, -1); $data = json_decode($response->body, true); if (is_null($data)) { return $this->error($this->location, JText::_('COM_MARKETPLACE_REPOSITORY_INVALID_RESPONSE')); } $this->name = $data['repository']['name']; } if ($this->location) { $key = $this->_tbl_key; $query = $this->_db->getQuery(true); $query->select($this->_tbl_key); $query->from($this->_tbl); $query->where('location=' . $this->_db->quote($this->location)); $this->_db->setQuery($query); $this->{$key} = $this->_db->loadResult(); } if ($this->{$key} == 0) { $this->published = 1; } return true; }
private function remoteContent($url) { $cache = JFactory::getCache('wow', 'output'); $cache->setCaching(1); $cache->setLifeTime($this->params->get('cache_time', 24) * 60 + rand(0, 60)); // randomize cache time a little bit for each url $key = md5($url); if (!($result = $cache->get($key))) { try { $http = new JHttp(new JRegistry(), new JHttpTransportCurl(new JRegistry())); $http->setOption('userAgent', 'Joomla! ' . JVERSION . '; WoW Raid Progress - WotLK; php/' . phpversion()); $result = $http->get($url, null, $this->params->get('timeout', 10)); } catch (Exception $e) { return $e->getMessage(); } $cache->store($result, $key); } if ($result->code != 200) { return __CLASS__ . ' HTTP-Status ' . JHtml::_('link', 'http://wikipedia.org/wiki/List_of_HTTP_status_codes#' . $result->code, $result->code, array('target' => '_blank')); } return json_decode($result->body); }
function onAjaxHelix3() { $input = JFactory::getApplication()->input; $action = $input->post->get('action', '', 'STRING'); if ($action == 'upload_image') { $this->upload_image(); return; } else { if ($action == 'remove_image') { $this->remove_image(); return; } } if ($_POST['data']) { $data = json_decode(json_encode($_POST['data']), true); $action = $data['action']; $layoutName = ''; if (isset($data['layoutName'])) { $layoutName = $data['layoutName']; } $template = self::getTemplate()->template; $layoutPath = JPATH_SITE . '/templates/' . $template . '/layout/'; $filepath = $layoutPath . $layoutName; $report = array(); $report['action'] = 'none'; $report['status'] = 'false'; switch ($action) { case 'remove': if (file_exists($filepath)) { unlink($filepath); $report['action'] = 'remove'; $report['status'] = 'true'; } $report['layout'] = JFolder::files($layoutPath, '.json'); break; case 'save': if ($layoutName) { $layoutName = strtolower(str_replace(' ', '-', $layoutName)); } $content = $data['content']; if ($content && $layoutName) { $file = fopen($layoutPath . $layoutName . '.json', 'wb'); fwrite($file, $content); fclose($file); } $report['layout'] = JFolder::files($layoutPath, '.json'); break; case 'load': if (file_exists($filepath)) { $content = file_get_contents($filepath); } if (isset($content) && $content) { echo $layoutHtml = self::loadNewLayout(json_decode($content)); } die; break; case 'resetLayout': if ($layoutName) { echo self::resetMenuLayout($layoutName); } die; break; // Upload Image // Upload Image case 'upload_image': echo "Joomla"; die; break; default: break; case 'voting': if (JSession::checkToken()) { return json_encode($report); } $rate = -1; $pk = 0; if (isset($data['user_rating'])) { $rate = (int) $data['user_rating']; } if (isset($data['id'])) { $id = str_replace('post_vote_', '', $data['id']); $pk = (int) $id; } if ($rate >= 1 && $rate <= 5 && $id > 0) { $userIP = $_SERVER['REMOTE_ADDR']; $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*')->from($db->quoteName('#__content_rating'))->where($db->quoteName('content_id') . ' = ' . (int) $pk); $db->setQuery($query); try { $rating = $db->loadObject(); } catch (RuntimeException $e) { return json_encode($report); } if (!$rating) { $query = $db->getQuery(true); $query->insert($db->quoteName('#__content_rating'))->columns(array($db->quoteName('content_id'), $db->quoteName('lastip'), $db->quoteName('rating_sum'), $db->quoteName('rating_count')))->values((int) $pk . ', ' . $db->quote($userIP) . ',' . (int) $rate . ', 1'); $db->setQuery($query); try { $db->execute(); $data = self::getItemRating($pk); $rating = $data->rating; $report['action'] = $rating; $report['status'] = 'true'; return json_encode($report); } catch (RuntimeException $e) { return json_encode($report); } } else { if ($userIP != $rating->lastip) { $query = $db->getQuery(true); $query->update($db->quoteName('#__content_rating'))->set($db->quoteName('rating_count') . ' = rating_count + 1')->set($db->quoteName('rating_sum') . ' = rating_sum + ' . (int) $rate)->set($db->quoteName('lastip') . ' = ' . $db->quote($userIP))->where($db->quoteName('content_id') . ' = ' . (int) $pk); $db->setQuery($query); try { $db->execute(); $data = self::getItemRating($pk); $rating = $data->rating; $report['action'] = $rating; $report['status'] = 'true'; return json_encode($report); } catch (RuntimeException $e) { return json_encode($report); } } else { $report['status'] = 'invalid'; return json_encode($report); } } } $report['action'] = 'failed'; $report['status'] = 'false'; return json_encode($report); break; //Font variant //Font variant case 'fontVariants': $template_path = JPATH_SITE . '/templates/' . self::getTemplate()->template . '/webfonts/webfonts.json'; $plugin_path = JPATH_PLUGINS . '/system/helix3/assets/webfonts/webfonts.json'; if (JFile::exists($template_path)) { $json = JFile::read($template_path); } else { $json = JFile::read($plugin_path); } $webfonts = json_decode($json); $items = $webfonts->items; $output = array(); $fontVariants = ''; $fontSubsets = ''; foreach ($items as $item) { if ($item->family == $layoutName) { //Variants foreach ($item->variants as $variant) { $fontVariants .= '<option value="' . $variant . '">' . $variant . '</option>'; } //Subsets foreach ($item->subsets as $subset) { $fontSubsets .= '<option value="' . $subset . '">' . $subset . '</option>'; } } } $output['variants'] = $fontVariants; $output['subsets'] = $fontSubsets; return json_encode($output); break; //Font variant //Font variant case 'updateFonts': jimport('joomla.filesystem.folder'); jimport('joomla.http.http'); $template_path = JPATH_SITE . '/templates/' . self::getTemplate()->template . '/webfonts'; if (!JFolder::exists($template_path)) { JFolder::create($template_path, 0755); } $url = 'https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyBVybAjpiMHzNyEm3ncA_RZ4WETKsLElDg'; $http = new JHttp(); $str = $http->get($url); if (JFile::write($template_path . '/webfonts.json', $str->body)) { echo "<p class='font-update-success'>Google Webfonts list successfully updated! Please refresh your browser.</p>"; } else { echo "<p class='font-update-failed'>Google Webfonts update failed. Please make sure that your template folder is writable.</p>"; } die; break; //Template setting import //Template setting import case 'import': $template_id = filter_var($data['template_id'], FILTER_VALIDATE_INT); if (!$template_id) { die; break; } $settings = $data['settings']; $db = JFactory::getDbo(); $query = $db->getQuery(true); $fields = array($db->quoteName('params') . ' = ' . $db->quote($settings)); $conditions = array($db->quoteName('id') . ' = ' . $db->quote($template_id), $db->quoteName('client_id') . ' = 0'); $query->update($db->quoteName('#__template_styles'))->set($fields)->where($conditions); $db->setQuery($query); $db->execute(); die; break; } return json_encode($report); } }
function getAvatarUrl($providerUserId, $nullForDefault = false, $params = null) { if (!$params) { $params = new JRegistry(); } $width = $params->get('width', 300); $nullString = $nullForDefault ? 'null' : 'notnull'; $avatarUrl = JFBCFactory::cache()->get('google.avatar.' . $nullString . '.' . $providerUserId . '.' . $width); if ($avatarUrl === false) { $profile = $this->fetchProfile($providerUserId, 'image'); $avatarUrl = $profile->get('image.url', null); // Check for default image if ($avatarUrl) { if ($nullForDefault) { $http = new JHttp(); $avatar = $http->get($avatarUrl); if ($avatar->code == 200 && $avatar->headers['Content-Length'] == 946) { $avatarUrl = null; } } if ($avatarUrl) { $avatarUrl = str_replace("?sz=50", "?sz=" . $width, $avatarUrl); } // get a suitably large image to be resized JFBCFactory::cache()->store($avatarUrl, 'google.avatar.' . $nullString . '.' . $providerUserId . '.' . $width); } } return $avatarUrl; }
/** * */ public function preview() { $my = JXFactory::getUser(); $fileid = JRequest::getVar('file_id'); $file = JTable::getInstance('File', 'StreamTable'); $jxConfig = new JXConfig(); $data = array(); $data['reload'] = false; if ($file->load($fileid) && $my->authorise('stream.file.download', $file) && ($jxConfig->isCrocodocsEnabled() || $jxConfig->isScribdEnabled())) { // Grab the uuid $uuid = $file->getParam('uuid'); $docid = $file->getParam('doc_id'); if ($jxConfig->isCrocodocsEnabled() && empty($uuid) || $jxConfig->isScribdEnabled() && empty($docid)) { // haven't been uploaded yet, upload and grab the uuid $store = $file->preparePreview(); // reload file for updated content $file->load($fileid); $uuid = $file->getParam('uuid'); $docid = $file->getParam('doc_id'); } // Check if file is ready $previewReady = $file->getParam('preview-ready'); $isViewable = false; if (empty($previewReady)) { if ($jxConfig->isCrocodocsEnabled()) { // Preview not ready, query status $options = new JRegistry(); $transport = new JHttpTransportCurl($options); $http = new JHttp($options, $transport); $response = $http->get('https://crocodoc.com/api/v2/document/status?token=' . $jxConfig->get(JXConfig::CROCODOCS) . '&uuids=' . $file->getParam('uuid')); $responseObj = json_decode($response->body); //print_r($responseObj); exit; if (!isset($responseObj->error)) { $isViewable = !empty($responseObj[0]->viewable); if ($isViewable) { $previewReady = true; $file->setParam('preview-ready', 1); $file->store(); } } } else { // Query Scribd Preview status $http = new JHttp(); $statusUrl = 'http://api.scribd.com/api?api_key=' . $jxConfig->get(JXConfig::SCRIBD_API) . '&doc_id=' . $file->getParam('doc_id') . '&method=docs.getConversionStatus&my_user_id=' . $file->user_id; $response = $http->get($statusUrl); $result = simplexml_load_string($response->body); if (isset($result->conversion_status) && $result->conversion_status == 'DONE') { $previewReady = true; $file->setParam('preview-ready', 1); $file->store(); } } } if ($previewReady && (!empty($uuid) || !empty($docid))) { if ($jxConfig->isCrocodocsEnabled()) { $session_id = $file->getParam('previewSession'); if (time() > $file->getParam('previewExpiry')) { // File uploaded, try to create session $options = new JRegistry(); $transport = new JHttpTransportCurl($options); $http = new JHttp($options, $transport); $response = $http->post('https://crocodoc.com/api/v2/session/create', array('token' => '$jxConfig->get(JXConfig::CROCODOCS)', 'uuid' => $file->getParam('uuid'))); //$response = $http->post( 'https://crocodoc.com/api/v2/session/create' , array('token' => 'Oe8fA1mQ59LSwtBlKy4Nkbvn', 'uuid' => $uuid ) ); $responseObj = json_decode($response->body); $session_id = $responseObj->session; // Store this session so that we don't have to fetch it again $file->setParam('previewSession', $session_id); $file->setParam('previewExpiry', time() + 60 * 50); // ste it 50 mins from now $file->store(); } $html = '<iframe style="border:0px;width:100%;height:100%" src="https://crocodoc.com/view/' . $session_id . '"></iframe>'; } else { $html = "<div id='embedded_doc' data-doc_id=\"" . $file->getParam("doc_id") . "\" data-access_key=\"" . $file->getParam("access_key") . "\"><a href='http://www.scribd.com'>Scribd</a></div>\t\t\t\t\t\t\n\t\t\t\t\t\t\t <script type=\"text/javascript\">\n\t\t\t\t\t\t\t\t// Instantiate iPaper\n\t\t\t\t\t\t\t\t\$(document).ready(function() {\n\t\t\t\t\t\t\t\t\tscribd_doc = scribd.Document.getDoc(\$('#embedded_doc').data('doc_id'), \$('#embedded_doc').data('access_key'));\n\t\t\t\t\t\t\t\t\t// Parameters\n\t\t\t\t\t\t\t\t\tscribd_doc.addParam('height', 750);\n\t\t\t\t\t\t\t\t\tscribd_doc.addParam('width', 750);\n\t\t\t\t\t\t\t\t\tscribd_doc.addParam('auto_size', true);\n\t\t\t\t\t\t\t\t\tscribd_doc.addParam('mode', 'slideshow');\n\t\t\t\t\t\t\t\t\tscribd_doc.addParam('jsapi_version', 2);\n\n\t\t\t\t\t\t\t\t\t// Attach event listeners\n\t\t\t\t\t\t\t\t\tscribd_doc.addEventListener('docReady', onDocReady);\n\n\t\t\t\t\t\t\t\t\t// Write the instance\n\t\t\t\t\t\t\t\t\tscribd_doc.write('embedded_doc');\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\tvar onDocReady = function(e) {\n\t\t\t\t\t\t\t\t\tscribd_doc.api.setPage(1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t// Bookmark Helpers\n\t\t\t\t\t\t\t\tvar goToPage = function(page) {\n\t\t\t\t\t\t\t\t\tif (scribd_doc.api){\n\t\t\t\t\t\t\t\t\t\tscribd_doc.api.setPage(page);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\tvar goToMiddle = function() {\n\t\t\t\t\t\t\t\t\tif (scribd_doc.api){\n\t\t\t\t\t\t\t\t\t\tgoToPage( Math.floor(scribd_doc.api.getPageCount()/2) );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tvar goToEnd = function() {\n\t\t\t\t\t\t\t\t\tif (scribd_doc.api) {\n\t\t\t\t\t\t\t\t\t\tgoToPage(scribd_doc.api.getPageCount());\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t </script>"; } $data['html'] = $html; } else { $data['reload'] = 1; $data['file_id'] = $fileid; $data['html'] = '<p>Please wait while we prepare your document</p>'; } } else { $data['html'] = "<p>Not allowed to preview.</p>"; } echo json_encode($data); exit; }
/** * Gets a list of the merged pull numbers. * * @param integer The pull/issue number. * * @return array * * @since 11.3 */ protected function getMergedPulls() { $cutoff = 10; $page = 1; $merged = array(); while ($cutoff--) { $http = new JHttp(); $r = $http->get('https://api.github.com/repos/joomla/joomla-platform/pulls?state=closed&page=' . $page++ . '&per_page=100'); $pulls = json_decode($r->body); // Check if we've gone past the last page. if (empty($pulls)) { break; } // Loop through each of the pull requests. foreach ($pulls as $pull) { // If merged, add to the white list. if ($pull->merged_at) { $merged[] = $pull->number; } } } return $merged; }
/** * Query from eBay API the JSON stream of item id given to render * * @param int $ItemID The eBay ID of object to query * * @return string */ public static function getEbayItem($ItemID) { $config = KunenaFactory::getConfig(); if (is_numeric($ItemID) && $config->ebay_api_key) { $options = new JRegistry(); $transport = new JHttpTransportStream($options); // Create a 'stream' transport. $http = new JHttp($options, $transport); $response = $http->get('http://open.api.ebay.com/shopping?callname=GetSingleItem&appid=' . $config->ebay_api_key . '&siteid=' . $config->ebay_language . '&responseencoding=JSON&ItemID=' . $ItemID . '&version=889&trackingid=' . $config->ebay_affiliate_id . '&trackingpartnercode=9'); if ($response->code == '200') { $resp = json_decode($response->body); return $resp; } } return ''; }
/** * Query from eBay API the JSON stream of item id given to render * * @param int $ItemID The eBay ID of object to query * * @return string */ public static function getEbayItem($ItemID) { $config = KunenaFactory::getConfig(); if (is_numeric($ItemID) && $config->ebay_api_key) { $options = new JRegistry(); $transport = new JHttpTransportStream($options); // Create a 'stream' transport. $http = new JHttp($options, $transport); $response = $http->get('http://open.api.ebay.com/shopping?callname=GetSingleItem&appid=' . $config->ebay_api_key . '&siteid=' . $config->ebay_language . '&responseencoding=JSON&ItemID=' . $ItemID . '&version=889&trackingid=' . $config->ebay_affiliate_id . '&trackingpartnercode=9'); if ($response->code == '200') { $resp = json_decode($response->body); if ($resp->Ack == 'Success') { $ebay_object = '<div style="border: 1px solid #e5e5e5;margin:10px;padding:10px;border-radius:5px">'; $ebay_object .= '<img src="https://securepics.ebaystatic.com/api/ebay_market_108x45.gif" />'; $ebay_object .= '<div style="margin:10px 0" /></div>'; $ebay_object .= '<div style="text-align: center;"><a href="' . $resp->Item->ViewItemURLForNaturalSearch . '"> <img src="' . $resp->Item->PictureURL[0] . '" /></a></div>'; $ebay_object .= '<div style="margin:10px 0" /></div>'; $ebay_object .= '<a href="' . $resp->Item->ViewItemURLForNaturalSearch . '">' . $resp->Item->Title . '</a>'; $ebay_object .= '<div style="margin:10px 0" /></div>'; $ebay_object .= $resp->Item->ConvertedCurrentPrice->CurrencyID . ' ' . $resp->Item->ConvertedCurrentPrice->Value; $ebay_object .= '<div style="margin:10px 0" /></div>'; if ($resp->Item->ListingStatus == "Active") { $ebay_object .= '<a class="btn" href="' . $resp->Item->ViewItemURLForNaturalSearch . '">' . JText::_('COM_KUNENA_LIB_BBCODE_EBAY_LABEL_BUY_IT_NOW') . '</a>'; } else { $ebay_object .= JText::_('COM_KUNENA_LIB_BBCODE_EBAY_LABEL_COMPLETED'); } $ebay_object .= '</div>'; return $ebay_object; } else { return '<b>' . JText::_('COM_KUNENA_LIB_BBCODE_EBAY_ERROR_WRONG_ITEM_ID') . '</b>'; } } } else { if (KunenaFactory::getUser()->isAdmin()) { return '<b>' . JText::_('COM_KUNENA_LIB_BBCODE_EBAY_INVALID_APPID_KEY') . '</<b>'; } } return ''; }
/** * Get the rate limit for the authenticated user. * * @return \JHttpResponse * * @since 3.0.0 */ public function getRateLimit() { $prepared = $this->prepareRequest('/rate_limit'); return $this->processResponse($this->client->get($prepared['url'], $prepared['headers'])); }
/** * Get a list of images to migrate * * @return step object */ public function getImage() { // Initialize jupgrade class $jupgrade = new jUpgrade(); // JHttp instance jimport('joomla.http.http'); $http = new JHttp(); $data = $jupgrade->getRestData(); // Getting the total $data['task'] = "image"; $data['files'] = 'images'; $response = $http->get($jupgrade->params->get('rest_hostname'), $data); $id = $this->_getID('files_images'); $id = $id + 1; $name = $this->_getImageName($id); $write = JFile::write(JPATH_ROOT . '/images.new/' . $name, $response->body); $this->_updateID($id, 'files_images'); }
/** * Combine files and set compress header for combined file. * * Below is an example of <b>$files</b> parameter to minify some stylesheets: * * <pre>array( * 'screen' => array('screen1.css', 'screen2.css'), * 'print' => array('print1.css', 'print2.css') * )</pre> * * And the return value after execution this method is: * * <pre>array( * 'screen' => 'absolute/path/to/combined/file', * 'print' => 'absolute/path/to/combined/file' * )</pre> * * For combine Javascript files, the <b>$files</b> parameter look like below: * * <pre>array( * 0 => array('script1.js', 'script2.js', 'script3.js', 'script4.js') * )</pre> * * @param string $path Absolute path to the directory for storing minified file. * @param string $type Either 'css' or 'js'. * @param array $list Array of files to combine. * @param boolean $isContent Set to true if $files contains file content instead of file path. * * @return array */ protected static function process($path, $type, $list, $isContent = false) { // Combine file content foreach ($list as $media => $files) { foreach ($files as $file) { isset($minified[$media]) or $minified[$media] = ''; if ($isContent) { $tmp = $file; } else { // Read file content if (substr($file, 0, 1) == '/') { // Get absolute file path $file = str_replace(JURI::root(true), JPATH_ROOT, $file); if (!($tmp = JFile::read($file))) { // Convert to full file URI $file = JURI::root() . $file; } } // If remote file, get its content via HTTP client if (substr($file, 0, 5) == 'http:' or substr($file, 0, 6) == 'https:') { $http = new JHttp(); $tmp = $http->get($file); if (!empty($tmp->body)) { $tmp = $tmp->body; } } } $minified[$media] .= "\n{$tmp}"; } } // Save combined file foreach ($list as $media => $files) { // Generate minification file path $minifiedFile = $path . DS . $type . '_' . md5(json_encode($files)) . '.php'; // Add header to compress asset file $minified[$media] = '<?php // Initialize ob_gzhandler function to send and compress data ob_start("ob_gzhandler"); // Send the requisite header information and character set header("content-type: ' . ($type == 'js' ? 'text/javascript' : 'text/css') . '; charset: UTF-8"); // Check cached credentials and reprocess accordingly header("cache-control: must-revalidate"); // Set variable for duration of cached content $offset = 365 * 60 * 60; // Set variable specifying format of expiration header $expire = "expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; // Send cache expiration header to the client broswer header($expire); ?> ' . self::cleanCode($minified[$media], $type); // Write minification file JFile::write($minifiedFile, $minified[$media]); // Store path to minification file $minified[$media] = $minifiedFile; } return $minified; }
/** * Get the last id from RESTful * * @access public * @return int The last id */ public function getLastIdRest() { jimport('joomla.http.http'); // JHttp instance $http = new JHttp(); $data = $this->getRestData(); // Getting the total $data['task'] = "lastid"; $data['table'] = $this->_step['name']; $lastid = $http->get($this->params->get('rest_hostname'), $data); return (int) $lastid->body; }
/** * Get a single row * * @return step object */ public function requestRest($task = 'total', $table = false) { // Initialize jupgrade class $jupgrade = new jUpgrade(); // JHttp instance jimport('joomla.http.http'); $http = new JHttp(); $data = $jupgrade->getRestData(); // Getting the total $data['task'] = $task; $data['table'] = $table; $request = $http->get($jupgrade->params->get('rest_hostname'), $data); return $request->body; }
/** * Internal function to perform the actual remote API call * * @param string $url Remote to the remote site * @param array $query Query parameters in key=>value array format * @return object */ private function executeJSONQuery($url, $query) { jimport('joomla.client.http'); $http = new JHttp(array( 'timeout' => 10 )); if($this->_verb == 'GET') { jimport('joomla.environment.uri'); $uri = new JURI($url); if(!empty($query)) { foreach($query as $k => $v) { $uri->setVar($k, $v); } } $response = $http->get($uri->toString()); } else { $response = $http->post($url, $query); } if($response->code != 200) { JLog::add('HTTP error '.$response->code, JLog::ERROR); throw new Exception(JText::sprintf('COM_AKEEBAEXAMPLE_APIERR_HTTPERROR',$response->code)); } $raw = $response->body; $startPos = strpos($raw,'###') + 3; $endPos = strrpos($raw,'###'); if( ($startPos !== false) && ($endPos !== false) ) { $json = substr($raw, $startPos, $endPos - $startPos); } else { $json = $raw; } $result = json_decode($json, false); if(is_null($result)) { JLog::add('JSON decoding error', JLog::ERROR); JLog::add($json, JLog::DEBUG); throw new Exception(JText::_('COM_AKEEBAEXAMPLE_APIERR_JSONDECODING')); } return $result; }