/** * Get addon data from gpEasy.com and display to user * */ function RemoteBrowse() { global $langmessage, $config, $dataDir; //search options if (isset($_GET['search_option'])) { $save = true; switch ($_GET['search_option']) { case 'version': unset($config['search_version']); break; case 'noversion': $config['search_version'] = false; break; default: $save = false; break; } if ($save) { admin_tools::SaveConfig(); } } //make a list of installed addon id's $this->installed_ids = array(); if (isset($config['addons']) && is_array($config['addons'])) { foreach ($config['addons'] as $addon_info) { if (isset($addon_info['id'])) { $this->installed_ids[] = $addon_info['id']; } } } includeFile('tool/RemoteGet.php'); //search settings $this->searchUrl = $this->path_remote; $this->searchOrderOptions['rating_score'] = $langmessage['Highest Rated']; $this->searchOrderOptions['downloads'] = $langmessage['Most Downloaded']; $this->searchOrderOptions['modified'] = $langmessage['Recently Updated']; $this->searchOrderOptions['created'] = $langmessage['Newest']; $_GET += array('q' => ''); if (isset($_REQUEST['page']) && ctype_digit($_REQUEST['page'])) { $this->searchPage = $_REQUEST['page']; } //version specific search $search_version = false; if (!isset($config['search_version']) || $config['search_version']) { $this->searchQuery .= '&ug=' . rawurlencode(gpversion); $search_version = true; } if (!empty($_GET['q'])) { $this->searchQuery .= '&q=' . rawurlencode($_GET['q']); } $this->SearchOrder(); $slug = 'Plugins'; if ($this->config_index == 'themes') { $slug = 'Themes'; } $src = addon_browse_path . '/' . $slug . '?cmd=remote&format=json&' . $this->searchQuery . '&page=' . $this->searchPage; // format=json added 4.6b3 //check cache $cache_file = $dataDir . '/data/_remote/' . sha1($src) . '.txt'; $use_cache = false; if (file_exists($cache_file) && filemtime($cache_file) + 26100 > time()) { $result = file_get_contents($cache_file); $use_cache = true; } else { $result = gpRemoteGet::Get_Successful($src); } //no response if (!$result) { if ($use_cache) { unlink($cache_file); } echo '<p>' . gpRemoteGet::Debug('Sorry, data not fetched') . '</p>'; return; } //serialized or json (serialized data may be cached) if (strpos($result, 'a:') === 0) { $data = unserialize($result); } elseif (strpos($result, '{') === 0) { $data = json_decode($result, true); } else { if ($use_cache) { unlink($cache_file); } $debug = array(); $debug['Two'] = substr($result, 0, 2); $debug['Twotr'] = substr(trim($result), 0, 2); echo '<p>' . gpRemoteGet::Debug('Sorry, data not fetched', $debug) . '</p>'; return; } //not unserialized? if (!is_array($data) || count($data) == 0) { if ($use_cache) { unlink($cache_file); } echo '<p>' . $langmessage['Sorry, data not fetched'] . ' (F3)</p>'; return; } //save the cache if (!$use_cache) { gpFiles::Save($cache_file, $result); } $this->searchMax = $data['max']; if (isset($data['per_page']) && $data['per_page']) { $this->searchPerPage = $data['per_page']; } else { $this->searchPerPage = count($data['rows']); } $this->ShowHeader(); $this->SearchOptions(); echo '<table class="bordered full_width">'; echo '<tr><th></th><th>' . $langmessage['name'] . '</th><th>' . $langmessage['version'] . '</th><th>' . $langmessage['Statistics'] . '</th><th>' . $langmessage['description'] . '</th></tr>'; $i = 0; if (count($data['rows'])) { foreach ($data['rows'] as $row) { echo '<tr class="' . ($i % 2 ? 'even' : '') . '">'; echo '<td>'; echo $this->DetailLink($row['type'], $row['id'], '<img src="' . $row['icon'] . '" height="100" width="100" alt=""/>', '', ' class="shot"'); echo '</td>'; echo '<td class="nowrap">'; echo '<b>' . $row['name'] . '</b>'; echo '<br/>'; echo $this->DetailLink($row['type'], $row['id']); echo ' | '; $this->InstallLink($row); echo '</td><td>'; echo $row['version']; echo '</td><td class="nowrap">'; echo sprintf($langmessage['_downloads'], number_format($row['downloads'])); echo '<br/>'; $this->CurrentRating($row['rating_weighted']); echo '<br/>'; echo $row['rating_count'] . ' ratings'; echo '</td><td>'; echo $row['short_description']; echo '</td></tr>'; $i++; } echo '</table>'; $this->SearchNavLinks(); } else { echo '</table>'; echo '<p>' . $langmessage['Sorry, nothing matched'] . '</p>'; } echo '<h3>Search Options</h3>'; echo '<ul>'; echo '<li>Limit results to addons that are compatible with your version of gpEasy (' . gpversion . ') '; if ($search_version) { echo '<b>' . $langmessage['On'] . '</b> '; echo common::Link($this->searchUrl, $langmessage['Off'], $this->searchQuery . '&search_option=noversion', ' data-cmd="gpajax"'); } else { echo common::Link($this->searchUrl, $langmessage['On'], $this->searchQuery . '&search_option=version', ' data-cmd="gpajax"'); echo ' <b>' . $langmessage['Off'] . '</b>'; } echo '</li>'; echo '</ul>'; }
/** * Update available package information from gpEasy.com * */ function DoRemoteCheck2() { global $config, $dataDir; $path = common::IdUrl(); //add any locally available themes with addon ids includeFile('tool/parse_ini.php'); $dir = $dataDir . '/themes'; $themes = scandir($dir); $theme_ids = array(); foreach ($themes as $name) { if ($name == '.' || $name == '..') { continue; } $full_dir = $dir . '/' . $name; $templateFile = $full_dir . '/template.php'; $ini_file = $full_dir . '/Addon.ini'; if (!file_exists($templateFile)) { continue; } $ini_info = array(); if (file_exists($ini_file)) { $ini_info = gp_ini::ParseFile($ini_file); } if (isset($ini_info['Addon_Unique_ID'])) { $theme_ids[] = $ini_info['Addon_Unique_ID']; } } $theme_ids = array_unique($theme_ids); if (count($theme_ids)) { $path .= '&th=' . implode('-', $theme_ids); } //get data from gpEasy $result = gpRemoteGet::Get_Successful($path); if (!$result) { $this->msg(gpRemoteGet::Debug('Sorry, data not fetched')); return false; } //zipped data possible as of gpEasy 4.1 /* if( function_exists('gzinflate') ){ $temp = gzinflate($result); if( $temp ){ $result = $temp; } } */ $result = trim($result); $array = json_decode($result, true); //json as of gpEasy 4.1 if (!is_array($array)) { $debug = array(); $debug['Type'] = gettype($array); $debug['json_last_error'] = json_last_error(); $debug['Two'] = substr($result, 0, 20); $this->msg(gpRemoteGet::Debug('Sorry, data not fetched', $debug)); return false; } if (!$array) { $debug = array(); $debug['Count'] = count($array); $debug['Two'] = substr($result, 0, 20); $this->msg(gpRemoteGet::Debug('Sorry, data not fetched', $debug)); return false; } $this->update_data['packages'] = array(); $core_version = false; foreach ($array as $info) { $id =& $info['id']; if (!is_numeric($id)) { continue; } if (!isset($info['type'])) { continue; } if ($info['type'] == 'core') { $id = 'core'; $core_version = $info['version']; } $this->update_data['packages'][$id] = $info; } if (isset($this->update_data['packages']['core'])) { $this->core_package = $this->update_data['packages']['core']; } return true; }