/** * @covers Instaphp\Instagram\Tags::Search */ public function testSearch() { $res = $this->object->search('insta', ['count' => 10]); $this->assertInstanceOf('\\Instaphp\\Instagram\\Response', $res); $this->assertNotEmpty($res->data); $this->assertEquals(200, $res->meta['code']); }
<?php /* ------------------------------------------ ------ About the search-tags script ------ ------------------------------------------ This script will allow search results to populate in an automatic dropdown list. These results pull from the tags that are available. */ // Append a wildcard if the last character isn't whitespace if (strlen($_POST['search']) > 2 and $_POST['search'] == rtrim($_POST['search'])) { $_POST['search'] .= "*"; } // Retrieve a list of tags $searchResults = Tags::search($_POST['search'], true, 0, 5); // Prepare the search dropdown echo '<ul>'; foreach ($searchResults as $result) { echo ' <li><a class="searchSel" href="/?tag=' . $result['id'] . '" onmousedown="window.location=\'/?tag=' . $result['id'] . '\'">' . $result['title'] . '</a></li>'; } echo '</ul>';
/** * Register plugin hooks * @static */ public static function __static() { /* * These registration functions are here rather than the classes that directly provide * their data (like Tags for tag_list or Posts for post_list) because putting them in * their respective classes would require that they be autoloaded on every page load * so that these functions could register their ajax endpoints. */ // Registers an auth_ajax endpoint for tag autocompletion self::register_auth_ajax('tag_list', function () { $tags = Tags::search($_GET['q']); $results = array(); foreach ($tags as $tag) { $results[] = array('id' => $tag->term_display, 'text' => $tag->term_display); } $ar = new AjaxResponse(); $ar->data = array('results' => $results, 'more' => false, 'context' => array()); $ar->out(); }); // Registers an auth_ajax endpoint for post autocompletion self::register_auth_ajax('post_list', function () { $posts = Posts::get(array('title_search' => $_GET['q'])); $results = array(); foreach ($posts as $post) { $results[] = array('id' => $post->id, 'text' => $post->title); } $ar = new AjaxResponse(); $ar->data = array('results' => $results, 'more' => false, 'context' => array()); $ar->out(); }); }
/** * Plugin hook filter for the values of a faceted search * @param array $other_values The incoming array of values for this facet * @param string $facet The selected facet * @param string $q A string filter for facet values * @return array The returned list of possible values */ public static function filter_facetvalues($other_values, $facet, $q) { switch ($facet) { case 'type': $values = array_keys(Post::list_active_post_types()); break; case 'status': $values = array_keys(Post::list_post_statuses()); break; case 'tag': $tags = Tags::search($q); $values = array(); foreach ($tags as $tag) { $values[] = $tag->term_display; } break; case 'author': $values = array(); $users = Users::get(array('criteria' => $q)); foreach ($users as $user) { $values[] = $user->username; } break; case 'before': case 'after': $values = array($q); break; } return array_merge($other_values, $values); }