/** * 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>'; }
/** * Get addon data from gpEasy.com and display to user * */ function RemoteBrowse() { global $langmessage, $config, $dataDir, $gpversion; //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'); $orderby = array(); $orderby['rating_score'] = $langmessage['Highest Rated']; $orderby['downloads'] = $langmessage['Most Downloaded']; $orderby['modified'] = $langmessage['Recently Updated']; $orderby['created'] = $langmessage['Newest']; $_GET += array('q' => ''); $this->searchPage = 0; if (isset($_REQUEST['page']) && ctype_digit($_REQUEST['page'])) { $this->searchPage = $_REQUEST['page']; } $this->searchQuery = 'cmd=remote'; //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']); } if (isset($_GET['order']) && isset($orderby[$_GET['order']])) { $this->searchOrder = $_GET['order']; $this->searchQuery .= '&order=' . rawurlencode($_GET['order']); } else { reset($orderby); $this->searchOrder = key($orderby); } $slug = 'Special_Addon_Plugins'; if ($this->config_index == 'themes') { $slug = 'Special_Addon_Themes'; } $src = $GLOBALS['addonBrowsePath'] . '/' . $slug . '?' . $this->searchQuery . '&page=' . $this->searchPage; //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); } if (!$result) { echo '<p>' . $langmessage['Sorry, data not fetched'] . ' (f1)</p>'; return; } if (strpos($result, 'a:') !== 0) { echo '<p>' . $langmessage['Sorry, data not fetched'] . ' (f2)</p>'; return; } $data = unserialize($result); if (count($data) == 0) { 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->searchOffset = $this->searchPage * $this->searchPerPage; $this->FindForm(); echo '<h2 class="hmargin">'; echo common::Link($this->browser_path, $this->manage_label); echo ' <span>|</span> '; if (!empty($_GET['q'])) { echo common::Link($this->browser_path, $this->find_label, 'cmd=remote'); echo ' » '; echo htmlspecialchars($_GET['q']); } else { echo $this->find_label; } echo '</h2>'; echo '<div class="gp_search_options">'; $this->SearchNavLinks(); echo '<div class="search_order">'; foreach ($orderby as $key => $label) { if ($key === $this->searchOrder) { echo '<span>' . $label . '</span>'; } else { echo common::Link($this->browser_path, $label, $this->searchQuery . '&order=' . $key); } } echo '</div></div>'; 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>'; $this->DetailLink($row, '<img src="' . $row['icon'] . '" height="100" width="100" alt=""/>', '', ' class="shot"'); echo '</td>'; echo '<td class="nowrap">'; echo '<b>' . $row['name'] . '</b>'; echo '<br/>'; $this->DetailLink($row); 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 showArray($row); 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->browser_path, $langmessage['Off'], $this->searchQuery . '&search_option=noversion', ' name="gpajax"'); } else { echo common::Link($this->browser_path, $langmessage['On'], $this->searchQuery . '&search_option=version', ' name="gpajax"'); echo ' <b>' . $langmessage['Off'] . '</b>'; } echo '</li>'; echo '</ul>'; }
/** * Try to fetch a response using RemoteGet to see if we're getting a 500 error * * @access public * @static * @since 1.7 * * @return boolean */ static function TestResponse() { //get url, force gp_rewrite to $new_gp_rewrite $rewrite_before = $_SERVER['gp_rewrite']; $_SERVER['gp_rewrite'] = true; common::SetLinkPrefix(); $abs_url = common::AbsoluteUrl('Site_Map', '', true, false); $_SERVER['gp_rewrite'] = $rewrite_before; common::SetLinkPrefix(); $result = gpRemoteGet::Get_Successful($abs_url); if (!$result) { return false; } return true; }
/** * Download the source code from gpeasy * */ function DownloadSource() { global $langmessage; $this->msg('Downloading version ' . $this->core_package['version'] . ' from gpEasy.com.'); /* for testing * $download = 'http://test.gpeasy.com/gpEasy_test.zip'; * $download = 'http://gpeasy.loc/x_gpEasy.zip'; */ $download = addon_browse_path . '/Special_gpEasy?cmd=download'; $contents = gpRemoteGet::Get_Successful($download); if (!$contents || empty($contents)) { $this->msg($langmessage['download_failed'] . '(1)'); return false; } $this->msg($langmessage['package_downloaded']); $md5 = md5($contents); if ($md5 != $this->core_package['md5']) { $this->msg($langmessage['download_failed_md5'] . '<br/>Downloaded Checksum (' . $md5 . ') != Expected Checksum (' . $this->core_package['md5'] . ')'); return false; } $this->msg($langmessage['download_verified']); //save contents $tempfile = $this->tempfile(); if (!gpFiles::Save($tempfile, $contents)) { $this->msg($langmessage['download_failed'] . ' (2)'); return false; } $this->core_package['file'] = $tempfile; return true; }
function Options_htaccess($site) { global $langmessage; includeFile('admin/admin_permalinks.php'); if (!gpRemoteGet::Test()) { return; } $site_info = $this->siteData['sites'][$site]; $site_url = $site_info['url']; $site_uniq = false; if (isset($site_info['gpuniq'])) { $site_uniq = $site_info['gpuniq']; } $file_path = $site . '/.htaccess'; if (file_exists($file_path)) { $original_contents = $contents = file_get_contents($file_path); } if (!isset($_POST['hide_index'])) { $to_hide_index = false; unset($this->siteData['sites'][$site]['hide_index']); $prefix = ''; } else { if (empty($site_url)) { message('A valid site url is required to hide index.php'); return false; } $array = @parse_url($site_url); $prefix =& $array['path']; $to_hide_index = $this->siteData['sites'][$site]['hide_index'] = true; } //add the gpeasy rules admin_permalinks::StripRules($contents); $contents .= admin_permalinks::Rewrite_Rules($to_hide_index, $prefix, $site_uniq); if (!gpFiles::Save($file_path, $contents)) { message($langmessage['OOPS'] . ' (Couldn\'t save .htaccess)'); return false; } //check for valid response when hiding index.php if ($to_hide_index) { $check_url = $site_url . '/Special_Site_Map'; $result = gpRemoteGet::Get_Successful($check_url); if (!$result) { message('Did not recieve valid response when fetching url without index.php: ' . htmlspecialchars($check_url)); gpFiles::Save($file_path, $original_contents); return false; } } return true; }
function DownloadSource(&$package) { global $langmessage, $addonBrowsePath; /* for testing * $download = 'http://test.gpeasy.com/gpEasy_test.zip'; * $download = 'http://gpeasy.loc/rocky/x_gpEasy_test.zip'; */ $download = $addonBrowsePath . '/Special_gpEasy?cmd=download&version=' . urlencode($package['version']) . '&file=' . urlencode($package['zip']); echo '<li>Downloading version ' . $package['version'] . ' from gpEasy.com.</li>'; $contents = gpRemoteGet::Get_Successful($download); if (!$contents || empty($contents)) { echo '<li>' . $langmessage['download_failed'] . ' (1)</li>'; return false; } echo '<li>' . $langmessage['package_downloaded'] . '</li>'; $md5 = md5($contents); if ($md5 != $package['md5']) { echo '<li>' . $langmessage['download_failed_md5']; echo '<br/>Downloaded Checksum (' . $md5 . ') != Expected Checksum (' . $package['md5'] . ')'; echo '</li>'; return false; } echo '<li>' . $langmessage['download_verified'] . '</li>'; //save contents $tempfile = $this->tempfile(); if (!gpFiles::Save($tempfile, $contents)) { message($langmessage['download_failed'] . ' (2)'); return false; } $package['file'] = $tempfile; return true; }
/** * Confirm getting the url retreives the current installation * */ public static function ConfirmGet($url, $check_redirect = true) { global $config; $result = gpRemoteGet::Get_Successful($url); if (!$result) { return false; } if (isset($config['gpuniq'])) { $mdu_check = substr(md5($config['gpuniq']), 0, 20); if (strpos($result, $mdu_check) === false) { return false; } } //if redirected, make sure it's on the same host if ($check_redirect && gpRemoteGet::$redirected) { $redirect_a = parse_url(gpRemoteGet::$redirected); $req_a = parse_url($url); if ($redirect_a['host'] !== $req_a['host']) { return false; } } return true; }