Exemple #1
0
 /**
  * constructor
  *
  * @param string $path_homedir Pickles のホームディレクトリのパス
  */
 public function __construct($path_homedir)
 {
     if (!array_key_exists('REMOTE_ADDR', $_SERVER)) {
         // commandline only
         if (realpath($_SERVER['SCRIPT_FILENAME']) === false || dirname(realpath($_SERVER['SCRIPT_FILENAME'])) !== realpath('./')) {
             if (array_key_exists('PWD', $_SERVER) && is_file($_SERVER['PWD'] . '/' . $_SERVER['SCRIPT_FILENAME'])) {
                 $_SERVER['SCRIPT_FILENAME'] = realpath($_SERVER['PWD'] . '/' . $_SERVER['SCRIPT_FILENAME']);
             } else {
                 // for Windows
                 // .px_execute.php で chdir(__DIR__) されていることが前提。
                 $_SERVER['SCRIPT_FILENAME'] = realpath('./' . basename($_SERVER['SCRIPT_FILENAME']));
             }
         }
     }
     chdir(dirname($_SERVER['SCRIPT_FILENAME']));
     $px = new px($path_homedir);
     // 最終出力
     switch ($px->req()->get_cli_option('-o')) {
         case 'json':
             $json = new \stdClass();
             $json->status = $px->get_status();
             $json->message = $px->get_status_message();
             $json->relatedlinks = $px->get_relatedlinks();
             $json->errors = $px->get_errors();
             $json->body_base64 = base64_encode($px->bowl()->pull());
             print json_encode($json);
             break;
         default:
             print $px->bowl()->pull();
             break;
     }
     exit;
 }
if ($page) {
    $class = "page";
    $response = curl("http://en.wikipedia.org/wiki/" . urlencode($page));
    $px = new px($response);
    $title = $px->xpath("//h1[@id='firstHeading']")->html();
    $titleText = $px->xpath("//h1[@id='firstHeading']")->text();
    $content = $px->xpath("//div[@id='mw-content-text']")->html();
} else {
    if (isset($about)) {
        $class = "about";
        $content = "\n\t<h1>What is this?</h1>\n\t<p>I love Wikipedia. It's awesome. But it deserves a better and more delightful design. This is my vision of how the reading experience should be like. Better typography, removed side bar, reduced clutter, improved contrast and clarity, and more open space.\n\t<p>This is just a concept. Some features are not supported, and custom formatting on some wikipedia pages might not look right. If you see anything like that, <a href='mailto:moe.salih@gmail.com'>let me know</a>. Or you can contribute to the project on <a href='https://github.com/moesalih/wikipedia.moesalih.com' target='_blank'>GitHub</a>.\n\t<p>If you like this redesign, please share it with your friends and spread the word. And if you have any feedback or if you just want to say hi, feel free to <a href='mailto:moe.salih@gmail.com'>email me</a>.<br /><br />\n\t<p>Moe Salih<br />\n\t<small><a href='http://moesalih.com'>moesalih.com</a></small>\n\t";
    } else {
        if ($search) {
            $class = "search";
            $response = curl("http://en.wikipedia.org/w/index.php?search=" . urlencode($search));
            $px = new px($response);
            $title = "<h1 id='firstHeading'>Search results</h1>";
            $titleText = $search;
            $content = $px->xpath("//ul[@class='mw-search-results']")->html();
        } else {
            $class = "home";
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
 public function get($args)
 {
     if ($this->fn) {
         $xml = isset($args) ? $this->fn->call(func_get_args()) : $this->fn->get();
         if (!isset($xml)) {
             return;
         }
         $this->val = px::XmlMakeDoc("<PX>{$xml}</PX>");
     }
     return $this->val->firstChild->childNodes;
 }