Ejemplo n.º 1
0
 /**
  * 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;
 }
 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);
 }
 public function getExtensions()
 {
     // Get catid, search filter, order column, order direction
     $cache = JFactory::getCache();
     $cache->setCaching(1);
     $http = new JHttp();
     $http->setOption('timeout', 60);
     $componentParams = JComponentHelper::getParams('com_apps');
     $api_url = new JUri();
     $default_limit = $componentParams->get('default_limit', 8);
     $input = new JInput();
     $catid = $input->get('id', null, 'int');
     $order = $input->get('ordering', $this->getOrderBy());
     $orderCol = $this->state->get('list.ordering', $order);
     $orderDirn = $orderCol == 'core_title' ? 'ASC' : 'DESC';
     $release = preg_replace('/[^\\d]/', '', base64_decode($input->get('release', '', 'base64')));
     $limitstart = $input->get('limitstart', 0, 'int');
     $limit = $input->get('limit', $default_limit, 'int');
     $dashboard_limit = $componentParams->get('extensions_perrow') * 6;
     // 6 rows of extensions
     $search = str_replace('_', ' ', urldecode(trim($input->get('filter_search', null))));
     $release = intval($release / 5) * 5;
     $api_url->setScheme('http');
     $api_url->setHost('extensions.joomla.org/index.php');
     $api_url->setvar('option', 'com_jed');
     $api_url->setvar('controller', 'filter');
     $api_url->setvar('view', 'extension');
     $api_url->setvar('format', 'json');
     $api_url->setvar('limit', $limit);
     $api_url->setvar('limitstart', $limitstart);
     $api_url->setvar('filter[approved]', '1');
     $api_url->setvar('filter[published]', '1');
     $api_url->setvar('extend', '0');
     $api_url->setvar('order', $orderCol);
     $api_url->setvar('dir', $orderDirn);
     if ($search) {
         $api_url->setvar('searchall', urlencode($search));
     }
     $extensions_json = $cache->call(array($http, 'get'), $api_url);
     $items = json_decode($extensions_json->body);
     $items = $items->data;
     // Populate array
     $extensions = array(0 => array(), 1 => array());
     foreach ($items as $item) {
         $item->image = $this->getBaseModel()->getMainImageUrl($item);
         if ($search) {
             $extensions[1 - $item->foundintitle][] = $item;
         } else {
             $extensions[0][] = $item;
         }
     }
     return array_merge($extensions[0], $extensions[1]);
 }
Ejemplo n.º 4
0
 public function getCategories($catid)
 {
     if (empty($this->_categories)) {
         $cache = JFactory::getCache();
         $http = new JHttp();
         $http->setOption('timeout', 60);
         $cache->setCaching(1);
         $categories_json = $cache->call(array($http, 'get'), 'http://extensions.joomla.org/index.php?option=com_jed&view=category&layout=list&format=json&order=order&limit=-1');
         $items = json_decode($categories_json->body);
         $this->_total = count($items);
         // Properties to be populated
         $properties = array('id', 'title', 'alias', 'parent');
         // Array to collect children categories
         $children = array();
         // Array to collect active categories
         $active = array($catid);
         $breadcrumbRefs = array();
         // Array to be returned
         $this->_categories = array();
         $this->_children = array();
         foreach ($items as $item) {
             // Skip root category
             if (trim(strtolower($item->title->value)) === 'root') {
                 continue;
             }
             $id = (int) $item->id->value;
             $parentId = (int) $item->parent_id->value;
             if ((int) $item->level->value > 1) {
                 // Ignore subitems without a parent.
                 if (is_null($item->parent_id->value)) {
                     continue;
                 }
                 // It is a child, so let's store as a child of it's parent
                 if (!array_key_exists($parentId, $this->_categories)) {
                     $this->_categories[$parentId] = new stdClass();
                 }
                 $parent =& $this->_categories[$parentId];
                 if (!isset($parent->children)) {
                     $parent->children = array();
                 }
                 if (!isset($parent->children[$id])) {
                     $parent->children[$id] = new stdClass();
                 }
                 $category =& $parent->children[$id];
                 // Populate category with values
                 $category->id = $id;
                 $category->active = $catid == $category->id;
                 $category->selected = $category->active;
                 $category->name = $item->title->value;
                 $category->alias = $item->alias->value;
                 $category->parent = (int) $parentId;
                 $category->description = '';
                 $category->children = array();
                 $this->_children[] = $category;
                 if ($category->active) {
                     $this->_categories[$parentId]->active = true;
                     if (!array_key_exists($parentId, $breadcrumbRefs)) {
                         $breadcrumbRefs[$parentId] =& $this->_categories[$parentId];
                     }
                     $breadcrumbRefs[$id] =& $category;
                 }
             } else {
                 // It is parent, so let's add it to the parent array
                 if (!array_key_exists($id, $this->_categories)) {
                     $this->_categories[$id] = new stdClass();
                     $this->_categories[$id]->children = array();
                 }
                 $category =& $this->_categories[$id];
                 $category->id = $id;
                 if (!isset($category->active)) {
                     $category->active = $catid == $category->id;
                 }
                 $category->selected = $category->active;
                 $category->name = $item->title->value;
                 $category->alias = $item->alias->value;
                 $category->parent = (int) $parentId;
                 $category->description = '';
                 if ($category->active) {
                     $breadcrumbRefs[$id] =& $category;
                 }
             }
         }
         if (!empty($catid)) {
             $this->_breadcrumbs = $breadcrumbRefs;
         }
     }
     // Add the Home item
     $input = new JInput();
     $view = $input->get('view', null);
     $home = new stdClass();
     $home->active = $view == 'dashboard' ? true : false;
     $home->id = 0;
     $home->name = JText::_('COM_APPS_HOME');
     $home->alias = 'home';
     $home->description = JText::_('COM_APPS_EXTENSIONS_DASHBOARD');
     $home->parent = 0;
     $home->selected = $view == 'dashboard' ? true : false;
     $home->children = array();
     array_unshift($this->_categories, $home);
     return $this->_categories;
 }
 public function getExtension()
 {
     // Get extension id
     $cache = JFactory::getCache();
     $cache->setCaching(1);
     $http = new JHttp();
     $http->setOption('timeout', 60);
     $api_url = new JUri();
     $input = new JInput();
     $id = $input->get('id', null, 'int');
     $release = preg_replace('/[^\\d]/', '', base64_decode($input->get('release', '', 'base64')));
     $release = intval($release / 5) * 5;
     $api_url->setScheme('http');
     $api_url->setHost('extensions.joomla.org/index.php');
     $api_url->setvar('option', 'com_jed');
     $api_url->setvar('controller', 'filter');
     $api_url->setvar('view', 'extension');
     $api_url->setvar('format', 'json');
     $api_url->setvar('filter[approved]', '1');
     $api_url->setvar('filter[published]', '1');
     $api_url->setvar('extend', '0');
     $api_url->setvar('filter[id]', $id);
     $extension_json = $cache->call(array($http, 'get'), $api_url);
     // Create item
     $items = json_decode($extension_json->body);
     $item = $items->data[0];
     $this->_catid = $item->core_catid->value;
     $item->image = $this->getBaseModel()->getMainImageUrl($item);
     $item->downloadurl = $item->download_integration_url->value;
     if (preg_match('/\\.xml\\s*$/', $item->downloadurl)) {
         $app = JFactory::getApplication();
         $product = addslashes(base64_decode($app->input->get('product', '', 'base64')));
         $release = preg_replace('/[^\\d\\.]/', '', base64_decode($app->input->get('release', '', 'base64')));
         $dev_level = (int) base64_decode($app->input->get('dev_level', '', 'base64'));
         $updatefile = JPATH_ROOT . '/libraries/joomla/updater/update.php';
         $fh = fopen($updatefile, 'r');
         $theData = fread($fh, filesize($updatefile));
         fclose($fh);
         $theData = str_replace('<?php', '', $theData);
         $theData = str_replace('$ver->PRODUCT', "'" . $product . "'", $theData);
         $theData = str_replace('$ver->RELEASE', "'" . $release . "'", $theData);
         $theData = str_replace('$ver->DEV_LEVEL', "'" . $dev_level . "'", $theData);
         eval($theData);
         $update = new JUpdate();
         $update->loadFromXML($item->downloadurl);
         $package_url_node = $update->get('downloadurl', false);
         if (isset($package_url_node->_data)) {
             $item->downloadurl = $package_url_node->_data;
         }
     }
     $item->download_type = $this->getTypeEnum($item->download_integration_type->value);
     return array($item);
 }