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 '
'.$langmessage['Addon_Install_Warning'].'
'; echo ''.sprintf($langmessage['Selected_Install'],$name,CMS_READABLE_DOMAIN).'
'; $_REQUEST += array('order'=>''); 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 ''; 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 ''.$langmessage['name'].' | '.$langmessage['version'].' | '.$langmessage['Statistics'].' | '.$langmessage['description'].' | |
---|---|---|---|---|
'; echo self::DetailLink($row['type'], $row['id'], '','',' class="shot"'); echo ' | '; 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 ' |
'; 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 ' '; } public function FindForm(){ global $langmessage; $_GET += array('q'=>''); echo ''; echo $langmessage['name']; echo ' | |
---|---|
'; echo htmlspecialchars($folder); echo ' | '; echo htmlspecialchars($msg); echo ' |