function search() { // load Zend classes require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Rest_Client'); // define category prefix $prefix = 'hollywood'; // initialize REST client $wikipedia = new Zend_Rest_Client('http://en.wikipedia.org/w/api.php'); // set query parameters $wikipedia->action('query'); $wikipedia->list('allcategories'); //All list queries return a limited number of results. $wikipedia->acprefix($prefix); $wikipedia->format('xml'); // perform request and iterate over XML result set $result = $wikipedia->get(); //echo "<ol>"; foreach ($result->query->allcategories->c as $c) { //<a href="http://www.wikipedia.org/wiki/Category: echo $c . "<br>"; } }
<?php /** * @file * @ingroup DAPCPTest * * @author Dian */ require_once 'Zend/Rest/Client.php'; $client = new Zend_Rest_Client('http://localhost/mw/api.php?action=wspcp&format=xml'); #$client->readPage("WikiSysop", NULL, NULL, NULL, NULL, "Main Page")->get(); $client->method("readPage"); $client->title("Main Page"); $result = $client->get(); var_dump($result->wspcp()->text); //echo $client->createPage("WikiSysop", NULL, NULL, NULL, NULL, "REST Test", "Adding some content")->get()->getIterator()->asXML(); //$__obj = $client->readPage("WikiSysop", NULL, NULL, NULL, NULL, "Main Page")->get(); //$__res = $__obj->__toString(); //var_dump($client->readPage("WikiSysop", NULL, NULL, NULL, NULL, "Main Page")->get()); //echo $client->login("WikiSysop", "!>ontoprise?")->get(); //var_dump($client->sayHello("Tester", "now")->get());
/** * rest-client.docx * Gets the first wiki-text before the Table of Content * @author TSCM * @since 20150102 * @param string - a Name or Booktitle , exp: "Lord of the Rings" * @return string - html code line * Explanation * //Base Url: * http://en.wikipedia.org/w/api.php?action=query * * //tell it to get revisions: * &prop=revisions * * //define page titles separated by pipes. In the example i used t-shirt company threadless * &titles=whatever|the|title|is * * //specify that we want the page content * &rvprop=content * * //I want my data in JSON, default is XML * &format=json * * //lets you choose which section you want. 0 is the first one. * &rvsection=0 * * //tell wikipedia to parse it into html for you * &rvparse=1 * * //only geht the "first"-Description of the wikipage, the one before the Table of Contents * &exintro=1 * * //if I want to select something, I use action query, update / delete would be different * &action=query */ public static function wiki($query) { // load Zend classes require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Rest_Client'); $decodeUtf8 = 0; //is decoding needed? Default not // define search query $wikiQuery = str_replace(" ", "_", $query); try { //initialize REST client $lang = I18n::lang(); $wikiLang = strtolower($lang); $webPagePrefix = "http://"; $webPageUrl = ".wikipedia.org/w/api.php"; //build the wiki api. be sure, that $wikiLang exists, exp: de or en $wikipedia = new Zend_Rest_Client($webPagePrefix . $wikiLang . $webPageUrl); $wikipedia->action('query'); //standard action, i want to GET... $wikipedia->prop('extracts'); //what do i want to extract? page info $wikipedia->exintro('1'); // only extract the intro? (pre-Table of content) 1= yes, 0=now $wikipedia->titles($wikiQuery); //title is the wiki title to be found $wikipedia->format('xml'); //what format should be returned? exp: json, txt, php, $wikipedia->continue(''); //has to be set, otherwise wikimedia sends a warning // perform request // iterate over XML result set $result = $wikipedia->get(); //print_r($result); $rs = $result->query->pages->page->extract; if ($decodeUtf8) { $rs = utf8_decode($rs); } //strip html Tags to get a clean string $rsFinal = strip_tags($rs); return $rsFinal; } catch (Exception $e) { die('ERROR: ' . $e->getMessage()); } }
/** * * @param <type> $pString * @return <type> */ public static function find_artist($pString) { $client = new Zend_Rest_Client("http://musicbrainz.org/ws/1/artist/"); $client->type('xml'); $client->name(str_replace(' ', '+', $pString)); return $client->get(); }
$taskr_site_url = "http://localhost:7007"; /** If your Taskr server is configured to require authentication, uncomment the next block and change the username and password to whatever you have in your server's config.yml. **/ //$username = '******'; //$password = '******'; //Zend_Rest_Client::getHttpClient()->setAuth($username, $password); /** Initialize the REST client. **/ $rest = new Zend_Rest_Client($taskr_site_url); /** Retreiving the list of all scheduled Tasks **/ $tasks = $rest->get("/tasks.xml"); // $tasks is a SimpleXml object, so calling print_r($result) will let // you see all of its data. // // Here's an example of how to print out all of the tasks as an HTML list: if ($tasks->task) { echo "<ul>\n"; foreach ($tasks->task as $task) { echo "\t<li>" . $task->name . "</li>\n"; echo "\t<ul>\n"; echo "\t\t<li>execute " . $task->{'schedule-method'} . " " . $task->{'schedule-when'} . "</li>\n"; echo "\t\t<li>created by " . $task->{'created-by'} . " on " . $task->{'created-on'} . "</li>\n"; echo "\t</ul>\n"; } echo "</ul>\n"; } else {
/** * * @param <type> $pSearch_string * @return <type> */ public static function search($pSearch_string) { $client = new Zend_Rest_Client("http://musicbrainz.org/ws/1/artist/"); $client->type('xml'); $client->name(str_replace(' ', '+', $pSearch_string)); $result = $client->get(); $out = array(); foreach ($result as $list) { foreach ($list->children() as $node_name => $node) { if ($node_name == 'artist') { $artist = new stdClass(); $attrs = $node->attributes(); $artist->mbid = (string) $attrs['id']; $artist->type = (string) $attrs['type']; $artist->name = (string) $node->name; $artist->disambiguation = (string) $node->disambiguation; $out[$artist->mbid] = $artist; } } } return $out; }
public function photoAction() { $this->_helper->viewRenderer->setNoRender(); //suppress auto-rendering $boolShowPhotos = false; $searchTag = $this->_request->getParam('searchTag'); $html = ''; if (empty($searchTag)) { $html .= "Please enter search keyword"; } else { try { $currentPage = 1; $i = $this->_request->getParam('page'); $currentPage = !empty($i) ? $i : 1; //initialize client with data set $client = new Zend_Rest_Client('http://api.flickr.com/services/rest/'); // set method name and API key $client->method('flickr.photos.search'); $client->api_key($this->flickrAPIKey); // set method arguments $client->tags($searchTag); // perform request and process response $result = $client->get(); $photos = array(); if (isset($result)) { foreach ($result->photos->photo as $photo) { $photos[] = array('thumbnail' => sprintf('http://farm%s.static.flickr.com/%s/%s_%s_t.jpg', $photo['farm'], $photo['server'], $photo['id'], $photo['secret']), 'original' => sprintf('http://farm%s.static.flickr.com/%s/%s_%s_b.jpg', $photo['farm'], $photo['server'], $photo['id'], $photo['secret']), 'title' => $photo['title'], 'ownername' => $photo['owner']); } } $html .= "<table align='center' width='90%' cellpadding='2' cellspacing='2'>"; if (!empty($photos)) { $paginator = Zend_Paginator::factory($photos); $paginator->setItemCountPerPage(5); $paginator->setPageRange(3); $paginator->setCurrentPageNumber($currentPage); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); $this->view->paginator = $paginator; Zend_Paginator::setDefaultScrollingStyle('Sliding'); if ($paginator) { $html .= "<tr><td colspan='5' align='center'>" . $paginator . "</td></tr>"; $html .= "<tr><td colspan='5' height='20'></td></tr>"; $html .= "<tr>"; $cnt = 1; foreach ($paginator as $photo) { $thumbnail = $photo['thumbnail']; $title = $photo['title']; $img = !empty($photo['original']) ? $photo['original'] : ''; $ownername = $photo['ownername']; $html .= "<td width='20%' align='center'>"; if (!empty($img)) { $html .= "<a href='" . $img . "' target='_blank'><img title='" . $title . "' class='thumb' src='" . $thumbnail . "'></a>"; $html .= "<br><a title='" . $ownername . "' href='" . $img . "' target='_blank'>{$ownername}</a>"; } else { $html .= "<img class='thumb' src='" . $thumbnail . "' title='" . $title . "'>"; $html .= "</br>" . $ownername; } $html .= "<br></td>"; $cnt++; } $html .= "</tr>"; $html .= "<tr><td colspan='5' height='20'></td></tr>"; $html .= "<tr><td colspan='5' align='center'>" . $paginator . "</td></tr>"; $html .= "</tr>"; } } else { $html .= "<tr><td colspan='5'><br><br><font color='red'>Sorry, No photos available.</td></tr>"; } $html .= "</table>"; } catch (Exception $e) { $html .= 'ERROR: ' . $e->getMessage(); } echo $html; } }
$wiki->setRenderConf('xhtml', 'wikilink', 'pages', false); // define page title $query = 'The A Team'; try { // initialize REST client $wikipedia = new Zend_Rest_Client('http://en.wikipedia.org/w/api.php'); // set query parameters $wikipedia->action('query'); $wikipedia->prop('revisions'); $wikipedia->rvprop('content'); $wikipedia->format('xml'); $wikipedia->redirects('1'); $wikipedia->titles($query); // perform request // get page content as XML $result = $wikipedia->get(); $content = $result->query->pages->page->revisions->rev; } catch (Exception $e) { die('ERROR: ' . $e->getMessage()); } ?> <html> <head> </head> <body> <h2>Page result for '<?php echo $query; ?> '</h2> <div> <?php