page->css_admin[] = '/include/css/addons.css'; $this->page->head_js[] = '/include/js/rate.js'; } /** * Output addon heading * */ public function ShowHeader( $addon_name = false ){ global $langmessage; //build links $header_paths = array(); $header_paths[$this->scriptUrl] = $langmessage['manage']; $header_paths[$this->scriptUrl.'/Available'] = $langmessage['Available']; if( $this->avail_count > 0 ){ $header_paths[$this->scriptUrl.'/Available'] = $langmessage['Available'].' ('.$this->avail_count.')'; } if( $this->config_index == 'themes' ){ $root_label = $langmessage['themes']; if( gp_remote_themes ){ $this->FindForm(); $header_paths[$this->scriptUrl.'/Remote'] = $langmessage['Search']; } }else{ $root_label = $langmessage['plugins']; if( gp_remote_plugins ){ $this->FindForm(); $header_paths[$this->scriptUrl.'/Remote'] = $langmessage['Search']; } } if( $addon_name ){ $header_paths = array(); $header_paths[$this->scriptUrl] = $langmessage['manage']; $header_paths[$this->page->requested] = $addon_name; } $list = array(); foreach($header_paths as $slug => $label){ if( $this->page->requested == $slug ){ $list[] = ''.$label.''; }else{ $list[] = \gp\tool::Link($slug,$label); } } echo '

'; echo $root_label; echo ' »'; echo implode('', $list ); echo '

'; } /** * Remote Install Functions * */ public function RemoteInstall(){ global $langmessage; echo '

'.$langmessage['Installation'].'

'; $name = ''.htmlspecialchars($_REQUEST['name']).''; echo '

'.$langmessage['Addon_Install_Warning'].'

'; echo '

'.sprintf($langmessage['Selected_Install'],$name,CMS_READABLE_DOMAIN).'

'; $_REQUEST += array('order'=>''); echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; } public function RemoteInstallConfirmed($type = 'plugin'){ $_POST += array('order'=>''); $installer = new \gp\admin\Addon\Installer(); $installer->code_folder_name = $this->code_folder_name; $installer->config_index = $this->config_index; $installer->InstallRemote( $type, $_POST['id'], $_POST['order'] ); $installer->OutputMessages(); return $installer; } /** * Get remote addon data and display to user * */ public function RemoteBrowse(){ global $langmessage, $config; $this->SearchOptionSave(); //make a list of installed addon id's $this->installed_ids = self::InstalledIds(); //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'=>''); $this->searchPage = \gp\special\Search::ReqPage('page'); //version specific search if( !isset($config['search_version']) || $config['search_version'] ){ $this->searchQuery .= '&ug='.rawurlencode(gpversion); } 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 $this->ShowHeader(); $data = $this->RemoteBrowseResponse($src); if( $data === false ){ return; } $this->searchMax = $data['max']; if( isset($data['per_page']) && $data['per_page'] ){ $this->searchPerPage = $data['per_page']; }else{ $this->searchPerPage = count($data['rows']); } $this->RemoteBrowseRows($data); $this->VersionOption(); } /** * Display option to limit search results to addons that are compat with the current cms version * */ public function VersionOption(){ global $langmessage, $config; echo '

'.$langmessage['options'].'

'; echo '

'; echo 'Limit results to addons that are compatible with your version of '.CMS_NAME.' ('.gpversion.')   '; if( !isset($config['search_version']) || $config['search_version'] ){ echo ''.$langmessage['On'].'   '; echo \gp\tool::Link($this->searchUrl,$langmessage['Off'],$this->searchQuery.'&search_option=noversion',' data-cmd="gpajax"'); }else{ echo \gp\tool::Link($this->searchUrl,$langmessage['On'],$this->searchQuery.'&search_option=version',' data-cmd="gpajax"'); echo '   '.$langmessage['Off'].''; } echo '

'; $this->ViewOnline(); } /** * Link to view search resuls on typesettercms.com * */ public function ViewOnline(){ $slug = 'Plugins'; if( $this->config_index == 'themes' ){ $slug = 'Themes'; } $url = addon_browse_path.'/'.$slug.'?'.$this->searchQuery.'&page='.$this->searchPage; echo '

View search results on '.CMS_READABLE_DOMAIN.'

'; } /** * Output the rows found by a RemoteBrowse search * */ public function RemoteBrowseRows($data){ global $langmessage; if( count($data['rows']) == 0 ){ echo '
'; echo '

'.$langmessage['Sorry, nothing matched'].'

'; echo '
'; return; } $this->SearchOptions(); echo ''; echo ''; foreach($data['rows'] as $row){ echo ''; echo ''; } echo '
'.$langmessage['name'].''.$langmessage['version'].''.$langmessage['Statistics'].''.$langmessage['description'].'
'; echo self::DetailLink($row['type'], $row['id'], '','',' class="shot"'); echo ''; echo ''.$row['name'].''; echo '
'; echo self::DetailLink($row['type'], $row['id'] ); echo ' | '; $this->InstallLink($row); echo '
'; echo $row['version']; echo ''; echo sprintf($langmessage['_downloads'],number_format($row['downloads'])); echo '
'; $this->CurrentRating($row['rating_weighted']); echo '
'; echo $row['rating_count'].' ratings'; echo '
'; echo $row['short_description']; echo '
'; $this->SearchNavLinks(); } /** * Return the list of installed addon ids * */ public static function InstalledIds(){ global $config; $ids = array(); if( isset($config['addons']) && is_array($config['addons']) ){ foreach($config['addons'] as $addon_info){ if( isset($addon_info['id']) ){ $ids[] = $addon_info['id']; } } } return $ids; } /** * Save the search option * */ private function SearchOptionSave(){ global $config; if( !isset($_GET['search_option']) ){ return; } switch($_GET['search_option']){ case 'version': unset($config['search_version']); break; case 'noversion': $config['search_version'] = false; break; default: return; } \gp\admin\Tools::SaveConfig(); } /** * Get cached data or fetch new response from server and cache it * */ public function RemoteBrowseResponse($src){ global $dataDir, $langmessage; $cache_file = $dataDir.'/data/_remote/'.sha1($src).'.txt'; $cache_used = false; //check cache if( file_exists($cache_file) && (filemtime($cache_file)+ 26100) > time() ){ $result = file_get_contents($cache_file); $cache_used = true; }else{ $result = \gp\tool\RemoteGet::Get_Successful($src); } $data = $this->ParseResponse($result); if( $data === false ){ $this->ViewOnline(); return false; } //not unserialized? if( count($data) == 0 ){ echo '

'; echo $langmessage['search_no_results']; echo '

'; return false; } //save the cache if( !$cache_used ){ \gp\tool\Files::Save($cache_file,$result); } return $data; } /** * Convert the response string to an array * Serialized or json (serialized data may be cached) * */ protected function ParseResponse($result){ //no response if( !$result ){ echo '

'.\gp\tool\RemoteGet::Debug('Sorry, data not fetched').'

'; return false; } $data = false; if( strpos($result,'a:') === 0 ){ $data = unserialize($result); }elseif( strpos($result,'{') === 0 ){ $data = json_decode($result,true); } if( !is_array($data) ){ $debug = array(); $debug['Two'] = substr($result,0,2); $debug['Twotr'] = substr(trim($result),0,2); echo '

'.\gp\tool\RemoteGet::Debug('Sorry, data not fetched',$debug).'

'; return false; } return $data; } public function SearchOrder(){ if( isset($_REQUEST['order']) && isset($this->searchOrderOptions[$_REQUEST['order']]) ){ $this->searchOrder = $_REQUEST['order']; $this->searchQuery .= '&order='.rawurlencode($_REQUEST['order']); }else{ reset($this->searchOrderOptions); $this->searchOrder = key($this->searchOrderOptions); } } /** * Display available search options * */ public function SearchOptions( $nav_on_top = true ){ echo '
'; if( $nav_on_top ){ $this->SearchNavLinks(); } echo '
'; foreach($this->searchOrderOptions as $key => $label){ if( $key === $this->searchOrder ){ echo ''.$label.''; }else{ echo \gp\tool::Link($this->searchUrl,$label,$this->searchQuery.'&order='.$key); } } echo '
'; if( !$nav_on_top ){ $this->SearchNavLinks(); } echo '
'; } public function FindForm(){ global $langmessage; $_GET += array('q'=>''); echo '
'; echo '
'; echo ' '; echo ''; echo '
'; echo '
'; } public function InstallLink($row){ global $config,$langmessage; $installed = in_array($row['id'],$this->installed_ids); if( !$installed && ($row['price_unit'] > 0) ){ $label = ' Install For $'.$row['price_unit']; echo self::DetailLink($row['type'], $row['id'], $label, '&cmd=install_info'); return; } if( $installed ){ $label = $langmessage['Update Now']; }else{ $label = $langmessage['Install Now']; } if( $row['type'] == 'theme' ){ $url = 'Admin_Theme_Content'; }else{ $url = 'Admin/Addons'; } $link = 'cmd=RemoteInstall'; $link .= '&name='.rawurlencode($row['name']); $link .= '&type='.rawurlencode($row['type']); $link .= '&id='.rawurlencode($row['id']); echo \gp\tool::Link($url,$label,$link); } public function SearchNavLinks(){ $pages = ceil($this->searchMax/$this->searchPerPage); echo '
'; \gp\special\Search::PaginationLinks( $this->searchPage, $pages, $this->searchUrl, $this->searchQuery, 'page'); echo '
'; } public function CurrentRating($rating){ $width = 16*5; $pos = min($width,ceil($width*$rating)); $pos2 = ($width-ceil($pos)); echo ''; echo ''; echo ''; echo ' '; } /** * Show folders in /addons that didn't make it into the available list * */ public function InvalidFolders(){ global $langmessage; if( empty($this->invalid_folders) ){ return; } echo '
'; echo '

Invalid Addon Folders

'; echo ''; echo ''; foreach($this->invalid_folders as $folder => $msg){ if( isset($this->avail_addons[$folder]) ){ continue; //skip false positives } echo ''; } echo '
'; echo $langmessage['name']; echo ' 
'; echo htmlspecialchars($folder); echo ''; echo htmlspecialchars($msg); echo '
'; } }