コード例 #1
0
 /**
  * Query the WP theme api for results.
  * @param  string $query search query
  * @return mixed        results or original query to fallback to provider search
  */
 function search($query)
 {
     if ($this->io->isVerbose()) {
         $this->io->write('Searching ' . self::apiUrl . ' for ' . $query);
     }
     try {
         $results = $this->queryAPI('query_themes', ['search' => $query]);
     } catch (RuntimeException $e) {
         if ($this->io->isVerbose()) {
             $this->io->writeError($e->getMessage());
         }
         // fall back to the standard search method
         return $query;
     }
     if (!empty($results['themes'])) {
         $out = [];
         $vendor = $this->repo->getDefaultVendor();
         foreach ($results['themes'] as $theme) {
             // fairly confident all of the fields below will be provided for a given theme
             $out[] = ['name' => "{$vendor}/{$theme['slug']}", 'description' => Util::truncate(strip_tags($theme['description']), 100), 'url' => $theme['homepage']];
         }
         return $out;
     }
     return $query;
 }
コード例 #2
0
 /**
  * Query the WP plugins api for results.
  * @param  string $query search query
  * @return mixed        results or original query to fallback to provider search
  */
 function search($query)
 {
     if ($this->io->isVerbose()) {
         $this->io->write("Searching for {$query}");
     }
     try {
         $results = $this->queryAPI('query_plugins', ['search' => $query]);
     } catch (RuntimeException $e) {
         if ($this->io->isVerbose()) {
             $this->io->writeError($e->getMessage());
         }
         // fall back to the standard search method
         return $query;
     }
     // query the api
     if (!empty($results->plugins)) {
         $vendor = $this->repo->getDefaultVendor();
         $out = [];
         foreach ($results->plugins as $plugin) {
             $out[] = ['name' => "{$vendor}/{$plugin->slug}", 'description' => Util::truncate(strip_tags($plugin->short_description), 100), 'url' => $plugin->homepage];
         }
         return $out;
     }
     return $query;
 }