コード例 #1
0
ファイル: DataGridColumn.php プロジェクト: jurasm2/datagrid
 /**
  * This method will be called when the component (or component's parent)
  * becomes attached to a monitored object. Do not call this method yourself.
  * @param  IComponent
  * @return void
  */
 protected function attached($dataGrid)
 {
     if ($dataGrid instanceof DataGrid) {
         $this->setParent($dataGrid->getComponent('columns', TRUE));
         if ($this->caption === NULL) {
             $this->caption = \Nette\String::capitalize($this->getName());
         }
     }
 }
コード例 #2
0
 private function canonicalizeDestination($destination)
 {
     // searching for any string that wikipedia knows
     $c = curl_init();
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
     curl_setopt($c, CURLOPT_USERAGENT, 'Travelbot 1.0 beta');
     curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE);
     curl_setopt($c, CURLOPT_MAXREDIRS, 100);
     $uri = new Uri('http://en.wikipedia.org/w/api.php');
     $uri->setQuery(array('format' => 'json', 'action' => 'opensearch', 'search' => $destination, 'limit' => 5));
     curl_setopt($c, CURLOPT_URL, (string) $uri);
     $result = curl_exec($c);
     curl_close($c);
     $json = json_decode($result);
     if ($json === FALSE) {
         throw new InvalidStateException('Malformed JSON response.');
     }
     if (!isset($json[1][0])) {
         throw new ArticleException('Article not found.');
     }
     $destination = $json[1][0];
     // canonization (redirection to the final article)
     $c = curl_init();
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
     curl_setopt($c, CURLOPT_USERAGENT, 'Travelbot 1.0 beta');
     curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE);
     curl_setopt($c, CURLOPT_MAXREDIRS, 100);
     $uri = new Uri('http://en.wikipedia.org/w/api.php');
     $uri->setQuery(array('format' => 'json', 'action' => 'query', 'titles' => $destination, 'redirects' => TRUE));
     curl_setopt($c, CURLOPT_URL, (string) $uri);
     $result = curl_exec($c);
     curl_close($c);
     $json = json_decode($result);
     if ($json === FALSE) {
         return $destination;
     }
     if (isset($json->query->redirects[0])) {
         return $json->query->redirects[0]->to;
     } else {
         if (isset($json->query->normalized[0])) {
             return String::capitalize($json->query->normalized[0]->to);
         }
     }
     return $destination;
 }